Recent Projects

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.

23 Responses to “WordPress Pagination on a Page”

  1. Brian says:

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

  2. 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…

  3. michel_X says:

    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 !

  4. reg says:

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

  5. [...] 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> [...]

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

  7. Keir says:

    Thank you for posting this – perfectly solved my problem!

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

  8. Andy says:

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

  9. Dami says:

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

  10. ffff00 says:

    Thank god, you just saved my life.

  11. Fred says:

    Thanks a ton! you save my time.

  12. Ashraf says:

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

    Hats Off :)

  13. John says:

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

  14. sampath says:

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

  15. Veronica says:

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

  16. rastapax says:

    gracias por el codigo

    excelent great thanks for the help

    cheers

  17. BGA says:

    Thanks! Badly needed this.

  18. Ricardo says:

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

  19. Thanks! Worked like a charm :)

  20. Jeff says:

    You are my hero.

  21. Dan says:

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

  22. Jeremy says:

    You win the internet.

  23. Jeremia says:

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

Leave a Reply