最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Pagination links for custom post type shows correct number of links, but links result in Page not found

programmeradmin0浏览0评论

This topic has many similar posts, but I'm not finding one that addresses my issue precisely.

Here is what I have done so far:

  1. I added a Custom Post Type to functions.php. This works. The imported posts show in the dashboard.

  2. I created a custom query to create a category page. This works, I can make it show a few or all of the records, but there are about a hundred posts in this category, so I need pagination.

  3. The pagination is producing the correct number of links, and the page addresses are incrementing accordingly.

Here is the code for the template:

<?php
  $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  $args = array(
    'post_type' => 'lumber',
    'posts_per_page' => 12,
    'paged' => $paged
  );
  $LumberQuery = new WP_Query( $args ); 
?>

<?php 
  if ( $LumberQuery->have_posts() ) : 
    //  echo $LumberQuery -> post_count;
  ?>

    <?php 
      while ( $LumberQuery->have_posts() ) : $LumberQuery->the_post(); 
                echo '<div class="ProductListing">';
                echo '<a href="'.get_permalink().'">';
                the_post_thumbnail( 'thumbnail' );
                echo '</a>';
                the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' );
                echo '</div><!-- End ProductListing div-->';
      endwhile; 
    ?>

    <div id="Pagination">
    <?php
      $big = 999999999; // need an unlikely integer
 
      echo paginate_links( array(
        'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
        'format' => '?paged=%#%',
        'current' => max( 1, get_query_var('paged') ),
        'total' => $LumberQuery->max_num_pages
       ) );
    ?>
    </div><!-- end pagination -->
    <?php wp_reset_postdata(); ?>

<?php endif; ?>

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论