Pagination on Wordpress static page set to front page?

I have a few different page templates that use the Wordpress loop to pull posts (examples would be a blog page, portfolio page, etc. that loop through and display posts differently). Everything (including pagination) works perfect when the page templates are applied to standard Wordpress pages.

My problem is that when you take one of these pages and set one to display as the Wordpress front page (in Settings > Reading > Front page displays), everything works except pagination. When you attempt to go to the next page of posts, the URL is correct in the browser, but it just keeps showing the first page of posts.

Is there some sort of trick to this? Has anyone accomplished this?

Add this to your query:

<?php
global $paged;
query_posts('paged='.$paged);
?>

I already have that in there.

The initial pagination works (as in the proper number of posts show up on the first page - what you get with the ‘paged’ argument - and the correct pagination buttons appear at the bottom of the loop). The problem is when you actually click to go to the next page, you are still presented with the first page’s posts.

This is currently how I have my loop setup:

<?php

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$query_string = 'paged=' . $paged;
query_posts($query_string); 
if (have_posts()) : while (have_posts()) : the_post();
?>

	... show posts ...

<?php endwhile; ?>


<?php if(function_exists('pagination')) { pagination(); } ?>
	
<?php else : ?>
	There are no posts to show.
<?php endif; ?>

Same thing happens to me when I set a static page that contains a loop with pagination, everything works in its normal context. Looks like it might be a bug. http://wordpress.org/support/topic/411884

Same thing happens to me when I set a static page that contains a loop with pagination, everything works in its normal context. Looks like it might be a bug. http://wordpress.org/support/topic/411884

@itsmattadams Thanks for the link. I’m going to try one of the workaround someone suggested on that thread.

I’d really like to find a good way to solve this because it would allow me to have a solid CMS theme on first install that someone could easily switch to a blog style theme if they wanted, which would be awesome for so many buyers.

And if anyone is curious about actually seeing what we’re talking about, I have posted a working version of one of my themes on a dummy site to show it:

Page with WP loop:

http://www.fuzzymule.com/?page_id=150

Page using the exact same page template, but set as the front page:

http://www.fuzzymule.com/

Try forming your query differently like so:

global $query_string;
$arg = 'enter your parameters here'

$posts = query_posts($query_string . '&'.$arg);

while (have_posts()) :

	the_post();

//output


endwhile; 

I have found that this always preserves the pagination.

Hope it helps

P.S This is found here: http://codex.wordpress.org/Function_Reference/query_posts#Usage_Note

Okay Guys! I’ve been searching WP forums and entire net for this. No results. Has anyone found a solution for having Pagination on static front page template?

This is the solution I found awhile back. It worked for me.

Instead of doing this:

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts( array( 'post_type' => 'post', 'paged' => $paged ) );

I do this:

if ( get_query_var('paged') ) {

	$paged = get_query_var('paged');
	
} elseif ( get_query_var('page') ) {

	$paged = get_query_var('page');
	
} else {

	$paged = 1;
	
}

query_posts( array( 'post_type' => 'post', 'paged' => $paged ) );

On my Complexity theme I did sort of the opposite of what you probably should do with a WordPress theme. The default setup looks like this:

http://themeblvd.com/demo/complexity-cms/

But then here’s a the blogroll page template set as the frontpage (under Settings > Reading> front page displays). And pagination is working using the method I showed above:

http://themeblvd.com/demo/complexity-blog/

Bravo! It worked perfectly. :slight_smile: Thanks a lot, Jason. That was tricky.

Hello ThemeBlvd
I’ve googled for this solution and found this post. But I’m still having a difficulty figuring out how I plugin this code to allow me to go to the next page of posts from homepage

Please let me know how I would do this, or which file is it suppose to go to.

So far what I did is added this code to my blog file

<?php if ( get_query_var('paged') ) {

    $paged = get_query_var('paged');

} elseif ( get_query_var('page') ) {

    $paged = get_query_var('page');

} else {

    $paged = 1;

}

query_posts( array( 'post_type' => 'post', 'paged' => $paged ) );
?>
	
<?php next_posts_link('') ?>
<?php previous_posts_link('') ?>

But when I click on More Posts, it doesnt take me to the next page although in the url bar it shows that it does.

Your help appreciated

Ben

I do this: if ( get_query_var('paged') ) { $paged = get_query_var('paged'); } elseif ( get_query_var('page') ) { $paged = get_query_var('page'); } else { $paged = 1; }
query_posts( array( 'post_type' => 'post', 'paged' => $paged ) );</blockquote>

Thank you ThemeBlvd. This worked for me, I’ve struggled with this issue for the last week.

1 Like

Thanks Jason

You posted your fix 4 years ago and I still had to scour the net to find the solution.

Thanks again

Thank you anriette… It works for me. :slight_smile: