• gavinwilshen

    (@gavinwilshen)


    WCBRS 2019 Contributor

    Hi

    After adding a new WP Query to a posts loop, the numeric post/page navigation is now incorrectly showing three pages when there should only be one. All three pages show the same 12 posts.

    The navigation works correctly if this new query (which limits the loop to only show posts from a single category) is removed and so I assume the navigation is counting all posts rather than just those within the category?
    new.boneshakermag.com/features/

    The function generating the pagination is below but this is outside of the loop. Any help or advice would be much appreciated.

    Many thanks,
    Gavin

    `if( ! function_exists(‘thb_numeric_pagination’) ) {
    /**
    * Add numeric pagination to the current loop.
    *
    * @param array $config The pagination configuration array.
    */
    function thb_numeric_pagination( $config=array() ) {
    global $wp_query;

    $args = wp_parse_args( $config, array(
    ‘range’ => 2
    ) );

    $showitems = ($args[‘range’] * 2) + 1;
    $paged = 1;

    // Getting pagination right
    if( isset($args[‘paged’]) ) {
    $paged = $args[‘paged’];
    }
    else {
    if ( get_query_var(‘paged’) ) {
    $paged = get_query_var(‘paged’);
    }
    elseif ( get_query_var(‘page’) ) {
    $paged = get_query_var(‘page’);
    }
    }

    // Number of pages from the query
    $pages = $wp_query->max_num_pages ? $wp_query->max_num_pages : 1;

    // Link back to the first page
    $show_first = ($paged > 2) && ($paged > $args[‘range’]+1) && ($showitems < $pages);

    // Link to the last page
    $show_last = ($paged < $pages-1) && ($paged+$args[‘range’]-1) < $pages && ($showitems < $pages);

    // Link to the next page
    $show_next = ($paged > 1) && ($showitems < $pages);

    // Link to the previous page
    $show_prev = ($paged < $pages) && ($showitems < $pages);

    if ( $pages != 1 ) {
    thb_get_template_part( ‘framework/templates/frontend/components/numeric_pagination’, array(
    ‘show_first’ => $show_first,
    ‘show_next’ => $show_next,
    ‘show_prev’ => $show_prev,
    ‘show_last’ => $show_last,
    ‘pages’ => $pages,
    ‘range’ => $args[‘range’],
    ‘paged’ => $paged,
    ‘showitems’ => $showitems,
    ‘link’ => ‘

    • %s
    • ‘,
      ‘current_link’ => ‘

    • <span class=”current”>%s</span>
    • ‘,
      ‘inactive_link’ => ‘

    • %s

    • ) );
      }
      }
      }’

  • The topic ‘[Theme: One] Numbered Post/Page Navigation incorrectly showing multiple pages’ is closed to new replies.