Display the Latest Posts with WordPress

If you set a static page as your front page, it can be a little tricky figuring out how to link to a page that shows your latest posts. So far I have come across two solutions you can use with your WordPress blog when linking to such a page.

Solution One

Create a link in your sidebar or somewhere on your site that looks like this: http://www.yourdomain.com/?p=all You should replace the http://www.yourdomain.com/ with the location of your blog.

Solution Two

You need to create a new page template by copying an existing one. In your new page template, find this line:

<?php while (have_posts()) : the_post(); ?>

Then replace that line with this code:

<?php $my_query = new WP_Query('showposts=10');

while ($my_query->have_posts()) : $my_query->the_post();

$do_not_duplicate = $post->ID; ?>

The code you just added creates a loop and retrieves the latest 10 posts and will display them on a page you create with your new template.

If you know of another solution to accomplish this task, please share it with my readers and me by commenting below.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Google
  • Technorati
  • Digg
  • del.icio.us
  • StumbleUpon
  • Sphinn
  • Facebook
  • Mixx

One Response to “Display the Latest Posts with WordPress”

  1. Hi,
    Question: If I want to put a or whatever to a page other than wordpress, eg. another website or another directory of the same domain, to show the latest several posts, what should I do with the html/php code? I definitely cannot use the wordpress functions…

Leave a Reply