Search code examples
wordpresspaginationwordpress-themingcustom-post-type

pagination on custom post wp_query


<?php
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $loop = new WP_Query(
            array(
                'post_type' => 'html5-blank',
                'posts_per_page' => 5,
                'paged'=>$paged
            )
        );
?>
<?php if ($loop->have_posts()): while ($loop->have_posts()) : $loop->the_post(); ?>      
 //Loop Code Here..
 <?php wp_reset_query(); ?> 
   <nav>
        <?php previous_posts_link( 'Newer posts &raquo;' ); ?>
        <?php next_posts_link('Older &raquo;') ?>
    </nav>
<?php endwhile; ?>
<?php else: ?>

Url on next page as I input result is: www.mywebsite.com/blog/page/2 is WORKING. But I can't show the pagination links.

Where did it go wrong?

EDIT: Pagination link is showing in page/2/ but not in the main blog page. Why?


Solution

  • I think you put <?php wp_reset_query(); ?> in the wrong place.. shouldn't it be next or after pagination codes?

    something like this

    <?php endwhile; ?>
    <?php else: ?>
    <?php wp_reset_query(); ?>