Support » Fixing WordPress » Pagination on static frontpage not working in custom post loop

  • Hi,

    I’ve read a few times that theres a bug in WordPress 3+ preventing pagination working on the homepage if a static page is selected.

    I have a custom post loop, and the pagination works on every page, bar the static homepage. If for example page ‘2’ is clicked, the URL will change to /page/2 but the content of page one remains visible and page 2 will not show.

    I’ve looked all over for a solution, and I think I’ve found one (user replied ‘it worked!’), but I’m not sure how to implement it. Could someone advise?

    The solution given is:

    Display posts from current page:

    $query = new WP_Query( array( 'paged' => get_query_var( 'paged' ) ) );

    Display posts from the current page and set the ‘paged’ parameter to 1 when the query variable is not set (first page).

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $query = new WP_Query( array( 'paged' => $paged ) );

    Pagination Note: Use get_query_var(‘page’); if you want your query to work in a Page template that you’ve set as your static front page. The query variable ‘page’ also holds the pagenumber for a single paginated Post or Page that includes the <!–nextpage–> Quicktag in the post content.

    Display posts from current page on a static front page:

    $paged = (get_query_var('page')) ? get_query_var('page') : 1;
    $query = new WP_Query( array( 'paged' => $paged ) );


    The code I need to implement this on looks like this….

    <?php if ( have_posts() )  ?>
    		<?php while ( have_posts() ) : the_post();  ?>
    <?php if( get_post_format() == 'quote' ) : ?>
    <div class="large-6 columns"><?php get_template_part( 'content-quote' ); ?></div>
    <?php elseif( get_post_format() == 'link' ) : ?>
    <div class="large-6 columns"><?php get_template_part( 'content-link' ); ?></div>
    <?php else : ?>
    <div class="large-6 columns"><?php get_template_part( 'content' ); ?></div>
    <?php endif; ?>
    <?php endwhile;
    //closing of the loop ?>
    <?php if ( function_exists( 'CUSTOM_pagination' ) ) {
    			} ?>

    Can anyone advise how to implement this WP_Query?


Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Pagination on static frontpage not working in custom post loop’ is closed to new replies.