In WordPress, when using query_posts(), why does pagination not work? -


this code in index.php. when click "older posts", still shows first page content. default loop works pagination.

    <?php      query_posts('showposts=10');     query_posts("cat=2");     if( have_posts() ):          while( have_posts() ): the_post(); ?>              <?php get_template_part('content',get_post_format()); ?>          <?php endwhile; ?>              <?php next_posts_link('« older posts'); ?>             <?php previous_posts_link('newer posts »'); ?>      <?php endif;         wp_reset_query();        ?>   

query_posts() not recommended use way, overwrite main query, , specific case, does not support pagination default. should use get_posts() or use wp_query object.

if must use query_posts(), there explanation on link above on how add paged parameter query.

here's same code, using get_posts().

<?php  $args = array('numberposts' => 10, 'category' => 2); $posts = get_posts($args); foreach($posts $post) {        // use $post object here in content template     <?php get_template_part('content',get_post_format()); ?> } <?php next_posts_link('« older posts'); ?> <?php previous_posts_link('newer posts »'); ?> 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -