WordPress Pagination on a Page

Posted by Trevor in Wordpress on December 21, 2006

One of the goals in redesigning this site was to reduce the amount of emphasis on the weblog - at least on the home page - without losing any standard blog functionality. I also tried to combine the weblog and the full archives on one page in the interest of saving space. I'm not sure how it'll scale, but it seems to work well enough for now.

The only problem I ran into in pushing the weblog off the front page was in using "pagination" from a "page". Pagination is easy when your blog is displayed from the home page, but there isn't any trick built into the query_posts() function to help if you're trying to display a standard blog from within a page.

After bumbling around for a while, I came across this small bit of code from Kafkaesqui that did the trick:

<?php $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts("showposts=5&paged=$page");
while ( have_posts() ) : the_post() ?>
<h2><a href="<?php the_permalink() ?>"><?php the_title() ?></a></h2>
<span class="entry-date"><?php the_time('F d, Y'); ?></span>
<?php the_content(); ?>
<?php endwhile ?>

I've added some code in there to complete the_loop as well. I'm sure this will come in handy as people continue to extend WordPress beyond what it was originally intended to do - and I hope this post can save some poor person on Google the headache I've got right now :)

Head over to the all new Weblog page to see the results of this endeavor, and make sure to click the "older posts" link at the bottom of the page.

11 Comments

 Brian

HOLY SHIT! THANK YOU SOOOOO MUCH! I have been trying to get this working for so long. I owe you one.

Wordpress Pagination Plugin For SEO…

How well are your older posts being crawled by search engines?
If your blog contains hundreds or thousands of posts you could be in DEEP trouble.
Pagination will place your older posts deeper and deeper in your directory. Several layers or several doze…

C O N G R A T U L A T I O N S for these two lines of code – a elegant respond to adapt special category webpage without using the default showposts set in options admin page.
Many than again !

 reg

wow, thanks for that! i’ve been looking around for something like that and it worked like a charm!

[...] search the web a little bit and found this.  So, I headed over to my theme designer and added the following code inside the <title> [...]

I use this little line almost in all of my work!

 Keir

Thank you for posting this – perfectly solved my problem!

Love the website/blog, btw. It’s beautiful clean and easy to read. Love it.

 Andy

Thanks! Been searching for how to do this for over an hour now.

 Dami

Thank you VERY MUCH!!!
I also was having problems with this.
Thanx for sharing!

 ffff00

Thank god, you just saved my life.

 Fred

Thanks a ton! you save my time.

Leave a comment

WP_Big_City