WordPress.org

Ready to get started?Download WordPress

Forums

Pagination on static frontpage not working in custom post loop (3 posts)

  1. mak1wp
    Member
    Posted 11 months ago #

    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>
    
    //ALL POST FORMATS
    
    <?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' ) ) {
    				required_pagination();
    			} ?>

    Can anyone advise how to implement this WP_Query?

    Thanks!

  2. esmi
    Forum Moderator
    Posted 11 months ago #

    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've not heard of any such "bug". And have you reviewed http://codex.wordpress.org/Function_Reference/WP_Query ?

  3. mak1wp
    Member
    Posted 11 months ago #

    Thanks esmi. Will post my progress on this.

Reply

You must log in to post.

About this Topic