WordPress.org

Ready to get started?Download WordPress

Forums

pagination (e.g. next_post_links) doesn't work on page of posts (6 posts)

  1. wmboy
    Member
    Posted 3 years ago #

    Here is my custom page;

    <?php query_posts($query_string . '&post_type=post'); ?>
    
    <?php get_template_part( 'loop', 'index' ); ?>

    ...and in my loop.php I've just got the standard pagination code;

    <?php if ( $wp_query->max_num_pages > 1 ) : ?>
    		<?php next_posts_link( __( '&larr; Older posts', 'twentyten' ) ); ?>
    		<?php previous_posts_link( __( 'Newer posts &rarr;', 'twentyten' ) ); ?>
    <?php endif; ?>

    Yet on this page, when I click on 'Older posts' it takes me to http://www.website.com/article-name/2/ but the pagination links are exactly the same (as if I was still on the 1st page). The blog posts have changed though.

    For the standard blog page the pagination links work fine.

  2. esmi
    Forum Moderator
    Posted 3 years ago #

    Try:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts($query_string . '&post_type=post&paged='. $paged'); ?
    ?>
  3. wmboy
    Member
    Posted 3 years ago #

    Many thanks for your response. I assume you meant this (the code above was invalid);

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts($query_string . '&post_type=post&paged='. $paged . '');
    ?>

    That doesn't work unfortunately. In fact it's worse than before as page 2 now displays the same posts as page 1 (as well as still not showing a 'Newer posts' link on page 2).

    Any further suggestions?

  4. wmboy
    Member
    Posted 3 years ago #

    Can I assume then that pagination isn't supposed to work on standard pages (only the blog index and category pages...)?

  5. esmi
    Forum Moderator
    Posted 3 years ago #

    You only get auto-pagination on post listing pages - not on static WP Pages. On the latter, you add a manual <!-- nextpage--> tag to break a large page up into multiple smaller sections.

  6. wmboy
    Member
    Posted 3 years ago #

    Hmmm, can I convert a static page into a post listing page?

    I already have category pages, and a blog page, and I am looking to customize the home page so that it acts as the normal blog page does (with pagination) but has additional home page content on it...).

Topic Closed

This topic has been closed to new replies.

About this Topic