I am trying to add pagination to category the URL comes out in the format as /category/cross-stitch/page/2/ but nothing shows on the page its going to 404. My code is below, which works for pagniation of posts that's not on the category.php template.
Does anyone know why this happens?
<?php
$categories = get_the_category();
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'post',
'cat' => $categories[0]->cat_ID,
'posts_per_page' => 2,
'paged' => $paged,
);
$products = new WP_Query( $args ); ?>
<div id="products">
<?php //Display the posts
if ($products->have_posts()) : while ($products->have_posts()) : $products->the_post(); ?>
<div class="item">
<!-- loops through -->
</div> <!-- .item -->
<?php endwhile; ?>
<div class="clear"></div>
<div class="pagniation-bot">
<div class="left">
<?php previous_posts_link( '← Previous'); ?>
</div><!-- .left -->
<div class="right">
<?php next_posts_link( 'Next →', $products -> max_num_pages ); ?>
</div><!-- /right -->
</div>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
</div> <!-- #products -->
Aucun commentaire:
Enregistrer un commentaire