0

I have the below code for a page, where I am pulling a photo, title and excerpt of the last 10 articles.

The problem is, I don't know how to add pagination?

I have installed WP-PageNavi aswell. I've seen some similar problems solved but I can't really get the concept at all and I am first trying to make sure that this is possible?

<?php /* Template Name: Opinion */ ?>
<?php get_header(); ?>
        <div id="primary">
        <div id="content" role="main">    
    <div class="clear"></div>  
<!---------------------------------------------------------------------------->
  <?php query_posts('cat=19&posts_per_page=10'); 
  if(have_posts()) : while(have_posts()) : the_post(); ?>
      <div class="pages-thumbs">
      <a href="<?php echo the_permalink(); ?>"><h2><?php the_title(); ?></h2></a>
      <?php the_post_thumbnail('medium'); ?>
      <div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
      <?php the_excerpt(); ?>
      </div>
      </div>
  <?php endwhile; endif; wp_reset_query(); ?>  
<!---------------------------------------------------------------------------->           
    </div><!-- #content -->
        </div><!-- #primary -->     
<?php get_sidebar(); ?>
<?php get_footer(); ?>

1 Answer 1

2

change this line:

<?php query_posts('cat=19&posts_per_page=10');  

to

<?php query_posts('cat=19&posts_per_page=10&paged='.get_query_var('paged'));  

and add the code for 'pagenavi' before the wp_reset_query();, for instance:

    <?php endwhile; endif; 
    if( function_exists('wp_pagenavi')) { wp_pagenavi(); }
else { posts_nav_link(); }
      wp_reset_query(); ?> 
1
  • Thank you very much, that did the trick. More important, I understand how to use it now, your post is sincerely appreciated. I also wanted to add a pharantesis as you've missed it but wouldn't let me as is less than 6 characters. For whoever else that needs this, change: if( function_exists('wp_pagenavi') to: if( function_exists('wp_pagenavi')) Commented Dec 20, 2011 at 9:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.