Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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(); ?>
share|improve this question
add comment

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(); ?> 
share|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')) –  Chris Demetriad Dec 20 '11 at 9:05
    
thanks - code is edited now ;-) –  Michael Dec 20 '11 at 9:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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