WordPress Pagination on a Page

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.

Advertisement

26 Responses to “WordPress Pagination on a Page”


  1. 1 Brian March 7, 2007 at 6:09 am

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

  2. 2 michel_X July 15, 2007 at 3:15 am

    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 !

  3. 3 reg June 24, 2008 at 9:38 pm

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

  4. 4 weston deboer October 8, 2008 at 9:47 am

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

  5. 5 Keir October 14, 2008 at 5:12 am

    Thank you for posting this – perfectly solved my problem!

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

  6. 6 Andy October 19, 2008 at 10:30 pm

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

  7. 7 Dami February 27, 2009 at 3:05 pm

    Thank you VERY MUCH!!!

    I also was having problems with this.

    Thanx for sharing!

  8. 8 ffff00 April 25, 2009 at 12:35 pm

    Thank god, you just saved my life.

  9. 9 Fred May 4, 2009 at 7:27 am

    Thanks a ton! you save my time.

  10. 10 Ashraf July 12, 2009 at 6:24 am

    Heyy Buddy… This is real cool :) I wish i would have found this blog a day ago…

    Hats Off :)

  11. 11 John July 24, 2009 at 7:00 pm

    WOW!! Thanks, this is exactly what I need, and it works perfectly. So simple, and so powerful =)

  12. 12 sampath July 29, 2009 at 8:40 am

    Very impressive, thank you Trevor, you saved my time. I love this blog. Thanks again.

  13. 13 Veronica October 14, 2009 at 6:47 pm

    This is exactly what I was looking for. Thank you so much!

  14. 14 rastapax December 5, 2009 at 12:49 pm

    gracias por el codigo

    excelent great thanks for the help

    cheers

  15. 15 BGA December 7, 2009 at 6:19 pm

    Thanks! Badly needed this.

  16. 16 Ricardo December 16, 2009 at 8:55 am

    Yeah!! My problem was solved too! Thank you!

  17. 17 Rodrigo Galindez December 16, 2009 at 12:05 pm

    Thanks! Worked like a charm :)

  18. 18 Jeff February 2, 2010 at 10:21 am

    You are my hero.

  19. 19 Dan February 23, 2010 at 1:28 pm

    DUDE – I have seriously been searching all day for this. If you we're in Denver I would buy you beer. Thanks for this!!!!!

  20. 20 Jeremy March 31, 2010 at 9:49 am

    You win the internet.

  21. 21 Jeremia April 16, 2010 at 5:23 pm

    Thanks a ton, have searched high and low for this solution to no avail. Works beautifully :-)

  22. 22 Engenharia September 4, 2010 at 1:58 pm

    The only pagination routine that really works. Thank you very much for your simple, yet fantastic, code.

  23. 23 chrisi May 6, 2011 at 10:24 am

    Now I would still like to know how to exclude one or more categories. any idea?

  24. 24 Rodrigo July 15, 2011 at 8:57 am

    Wow, thanks! First result in google and I have the answer. No headache, thank you! =D


  1. 1 Search Engine Optimization for Wordpress Blogs Trackback on April 28, 2007 at 5:37 am
  2. 2 Life Documentation by Chris Thompson » Blog Archive » SEO Problems with WordPress Pagination Trackback on September 30, 2008 at 9:06 pm
Comments are currently closed.




Follow

Get every new post delivered to your Inbox.