Plugin Directory

Changeset 2530086


Ignore:
Timestamp:
05/12/2021 12:59:07 AM (5 years ago)
Author:
oceas
Message:

Added pagination support to list view

Location:
connected-sermons/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • connected-sermons/trunk/Includes/shortcode-functions.php

    r2517230 r2530086  
    4949     * @since  NEXT
    5050     */
    51     public function sermons_list()
     51    public function sermons_list( $args )
    5252    {
     53        $page_size = absint( sanitize_text_field( $args['num_sermons'] ) );
     54        if ( 0 === $page_size ) {
     55            $page_size = 10;
     56        }
     57        set_query_var( 'page_size', $page_size );
    5358        ob_start();
    5459        cacs_get_part( 'list-view' );
  • connected-sermons/trunk/Includes/template-functions.php

    r2517230 r2530086  
    242242    return \ChurchAgency\ConnectedSermons\cs_fs()->is_not_paying();;
    243243}
     244
     245/**
     246 * Whether There is Old Content based on page location.
     247 *
     248 * @author Scott Anderson <[email protected]>
     249 * @since  1.0.5
     250 * @param  int $page_number Current Page Number
     251 * @param  int $page_size Page Size of Content.
     252 * @param  int $total_count Total Number of Content.
     253 * @return bool
     254 */
     255function cacs_older_content(int $page_number, int $page_size, int $total_count): bool
     256{
     257    $total_pages = cacs_total_pages($page_size, $total_count);
     258
     259    if ($total_count == 0 || $page_number >= $total_pages) {
     260        return false;
     261    }
     262
     263    return true;
     264}
     265
     266/**
     267 * Whether There is Newer Content based on page location.
     268 *
     269 * @author Scott Anderson <[email protected]>
     270 * @since  1.0.5
     271 * @param  int $page_number Current Page Number
     272 * @param  int $page_size Page Size of Content.
     273 * @param  int $total_count Total Number of Content.
     274 * @return bool
     275 */
     276function cacs_newer_content(int $page_number, int $page_size, int $total_count): bool
     277{
     278    $total_pages = cacs_total_pages($page_size, $total_count);
     279
     280    if ($total_count == 0 || $page_number == 0 || $page_number > $total_pages) {
     281        return false;
     282    }
     283
     284    return true;
     285}
     286
     287/**
     288 * Returns how many total pages exist for a given content type.
     289 *
     290 * @author Scott Anderson <[email protected]>
     291 * @since  1.0.5
     292 * @param  int $page_size Page Size of Content.
     293 * @param  int $total_count Total Number of Content.
     294 * @return bool
     295 */
     296function cacs_total_pages(int $page_size, int $total_count): int
     297{
     298    return absint(ceil($total_count / $page_size)) - 1;
     299}
  • connected-sermons/trunk/connected-sermons.php

    r2517230 r2530086  
    55 * Plugin URI: https://church.agency/connected-sermons/
    66 * Description: Easily add audio and video sermons to your church's website.
    7  * Version: 1.0.4
     7 * Version: 1.0.5
    88 * Author: Church Agency
    99 * Author URI: https://church.agency/
  • connected-sermons/trunk/readme.txt

    r2520094 r2530086  
    11=== Connected Sermons ===
    2 Contributors: oceas
     2Contributors: oceas, freemius
    33Tags: sermons, series, books, bible, preacher, church
    44Requires at least: 5.6.0
     
    7878## Changelog ##
    7979
     80### 1.0.5 - May 11, 2021 ###
     81* New: Added pagination support to sermons list.
     82
    8083### 1.0.4 - April 10th, 2021 ###
    8184* New: Main admin page with documentation links.
  • connected-sermons/trunk/views/partials/list-view.php

    r2517230 r2530086  
    88 * @package church
    99 */
     10
     11if (isset($_GET['cs_page'])) {
     12    $page_num = sanitize_text_field($_GET['cs_page']);
     13} else {
     14    $page_num = 0;
     15}
     16
     17$total_count = absint(wp_count_posts('cs_sermons')->publish);
     18$offset = $page_num * $page_size;
    1019
    1120$preachers = get_terms([
     
    3241    $args = [
    3342        'post_type'   => 'cs_sermons',
    34         'numberposts' => -1,
     43        'numberposts' => $page_size,
    3544        'tax_query'   => [
    3645            [
     
    4352        'meta_key' => 'cs_date',
    4453        'order'    => 'DES',
     54        'offset' => $offset,
    4555    ];
    4656} else {
    4757    $args = [
    4858        'post_type'   => 'cs_sermons',
    49         'numberposts' => -1,
     59        'numberposts' => $page_size,
    5060        'orderby'  => 'meta_value',
    5161        'meta_key' => 'cs_date',
    5262        'order'    => 'DES',
     63        'offset' => $offset,
    5364    ];
    5465}
     
    111122    </div>
    112123
     124    <?php if (-1  != $page_size) : ?>
     125        <div class="row">
     126            <div class="col">
     127                <?php if (cacs_newer_content($page_num, $page_size, $total_count)) : ?>
     128                    <a class="btn btn-outline-primary" href="?cs_page=<?php echo $page_num - 1; ?>"> <?php echo __('Newer Sermons', 'connected_sermons') ?> </a>
     129                <?php endif; ?>
     130
     131            </div>
     132            <div class="col text-right">
     133                <?php if (cacs_older_content($page_num, $page_size, $total_count)) : ?>
     134                    <a class="btn btn-outline-primary" href="?cs_page=<?php echo $page_num + 1; ?>"> <?php echo __('Previous Sermons', 'connected_sermons') ?> </a>
     135                <?php endif; ?>
     136            </div>
     137        </div>
     138    <?php endif; ?>
     139
    113140</main><!-- #main -->
Note: See TracChangeset for help on using the changeset viewer.