0

I don't know what to do here but pagination is driving me crazy! As you can see, "Older" points to blog/page/2 but when clicked, the site stays on blog/.

I'm using wp-pagenavi for pagination.

The site url is http://www.grassroottech.com/blog

Sorry, here is the blog template page: (embedding not working - http://pastebin.com/AtU7AYfD)

blog template

    <ul id="listlatestnews">
<?php
//Fix homepage pagination
if ( get_query_var('paged') ) { $paged = get_query_var('paged'); } else if ( get_query_var('page') ) {$paged = get_query_var('page'); } else {$paged = 1; }

$temp = $wp_query;  // re-sets query
$wp_query = null;   // re-sets query
$args = array( 'post_type' => array('post'), 'orderby'=>'date', 'order'=>'DESC', 'posts_per_page' => 10, 'paged' => $paged);
$wp_query = new WP_Query();
$wp_query->query( $args );
while ($wp_query->have_posts()) : $wp_query->the_post(); 
?>
      <li>
        <div class="boximg-blog">
        <?php if (function_exists('has_post_thumbnail') && has_post_thumbnail()) {?>
          <div class="blogimage">
            <img src="<?php echo get_template_directory_uri();?>/timthumb.php?src=<?php echo thumb_url();?>&amp;h=84&amp;w=84&amp;zc=1" alt="" class="boximg-pad" />
          </div>
        <?php } ?>
        </div>
        <div class="postbox <?php post_class(); ?>">
        <h3><a href="<?php the_permalink();?>"><?php the_title();?></a></h3>
        <p>
       <?php the_excerpt(__('Continue reading »','example')); ?>
        </p>
       </div>
       <div class="clear"></div>
        <div class="metapost">
          <span class="first"><?php echo __('Posted at ','ecobiz');?><?php the_time( get_option('date_format') ); ?></span> | 
          <span><?php echo __('By ','ecobiz');?>: <?php the_author_posts_link();?></span>  |                         
          <span><?php echo __('Categories ','ecobiz');?>: <?php the_category(',');?></span>  | 
          <span><?php comments_popup_link(__('0 Comment','ecobiz'),__('1 Comment','ecobiz'),__('% Comments','ecobiz'));?></span>
        </div>           
        <div class="clear"></div>
      </li>
    <?php endwhile; ?>

      </ul>
5
  • "Any ideas?" ... Yes: Share your code with us (instead of linking to external sources).
    – kaiser
    Commented Jan 15, 2013 at 18:49
  • unfortunately, the tutorial you've followed is a bad example of how to go about this. just designate a page for posts under Settings > Reading, use the standard template without calling query_posts, and avoid these pagination issues altogether.
    – Milo
    Commented Jan 15, 2013 at 18:56
  • 1) Please update your question with additional information and avoid leaving other comments (you can delete your own comments - a.k.a. "clean up task") 2) I wrote "instead of linking to external sources" above, so please "edit" your question and post the pastebin content.
    – kaiser
    Commented Jan 15, 2013 at 18:58
  • Milo, unfortunately that doesn't seem to work with this theme. When I set it to "Default", /blog looks identical to the front page.
    – Ash
    Commented Jan 15, 2013 at 19:10
  • @Ash because your theme is using the same template files for both pages, see the template hierarchy for info on how WordPress selects templates for front/home/posts pages.
    – Milo
    Commented Jan 16, 2013 at 5:09

2 Answers 2

0

I think that page has the pagination links wrong.

http://codex.wordpress.org/Function_Reference/previous_posts_link

previous_posts_link( $label , $max_pages );

Try just taking the $max_pages out, like:

<?php previous_posts_link('« Newer') ?>
<?php next_posts_link('Older »') ?>
1
  • I don't think I have $max_pages in at all.
    – Ash
    Commented Jan 15, 2013 at 19:04
0

This one done a good job for me. It checks the max_num_pages, then paged 'em.

<?php global $wp_query; $total_pages = $wp_query->max_num_pages; if ( $total_pages > 1 ) { ?>
<div id="nav-below" class="navigation">
<div class="nav-previous"><?php next_posts_link(__( '<span class="meta-nav">&laquo;</span> Older posts', 'nanodesigns' )) ?></div>
<div class="nav-next"><?php previous_posts_link(__( 'Newer posts <span class="meta-nav">&raquo;</span>', 'nanodesigns' )) ?></div>
</div><!-- #nav-below -->
<?php } ?>

Code courtesy Ian Stewart

After some of the comments below, the Phase II:
So, I think the problem is on the very first query of the page.

    <?php
    $paged = get_query_var('paged') ? get_query_var('paged') : 1;
    query_posts( array( 'cat' => -0, 'paged'=> $paged ) );
    if ( have_posts() ) : $count = 0; while ( have_posts() ) : the_post(); $count++;
    ?>

First of all: query_posts() is not a good way, it modifies the wp loop (ref). If you need any custom query, use WP_Query() instead.

Why shouldn't you start the page simply with the basic WP loop (instead of the code block I assumed may be problematic):

<?php while ( have_posts() ) : the_post() ?>

And at the bottom of the page, use the pagination code I pasted above.

7
  • Thanks, but same problem! The link points to blog/page/2 but blog/ loads.
    – Ash
    Commented Jan 15, 2013 at 19:48
  • So, here it comes, the problem is not the pagination code, but the blog post/page. Your question is unclear to us. You need to rewrite/edit your question to inform 2 things, if I got you right: (1) You need a post with comments, (2) You need a post with comments paginated, (3) But when you click on the pagination of the comment, you want a separate page of comments. Is that right? Commented Jan 15, 2013 at 19:55
  • If I got you correctly, then look at Tosco's recent answer on a new question here. Commented Jan 15, 2013 at 20:06
  • Hello Mayeenul. My issue has nothing to do with comments. I merely have a blog posts template that I want to display my latest 10 blog posts with pagination. The problem is that no matter what pagination I use, it will not work: click on page 2 and it will just load /blog instead of /blog/page/2.
    – Ash
    Commented Jan 15, 2013 at 20:20
  • Have a look @ the new updates, in this thread, is that works for you? Commented Jan 16, 2013 at 6:06

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