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(); ?>
link|improve this question

feedback

1 Answer

up vote 2 down vote accepted

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(); ?> 
link|improve this answer
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')) – Cristian Demetriad Dec 20 '11 at 9:05
thanks - code is edited now ;-) – Michael Dec 20 '11 at 9:13
feedback

Your Answer

 
or
required, but never shown

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