How to display latest posts from a single category in WordPress

By richardbaxterseo |

How to display latest posts from a specific category without a plugin in WordPress

I’ve just made an addition to my side bar that displays all of the latest items added to my SEO jobs category. It’s a few, simple lines of code and doesn’t nessecary warrant an entire plugin! Here’s how to do it – just insert the code below, and change the category=1 argument to the category number of your choice:

<ul>
<?php
global $post;
$myposts = get_posts('numberposts=5&offset=1&category=1');
foreach($myposts as $post) :
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>

The problem I’m trying to solve is why this job is not displaying on the list even though it’s in the same category as all the others. Any ideas? :-)

I’m off to play with Ubuntu Intrepid Ibex now. expect a report, soon!

6 Responses to “How to display latest posts from a single category in WordPress”

Leave a comment
  1. Posted October 31, 2008 at 7:35 am | Permalink

    The &offset=1 prevents the most recent post (or job) to show up, so removing that part should do the trick.

    • Posted September 17, 2009 at 9:37 am | Permalink

      thanks for that

      worked a treat when &offset=1 is dropped

  2. Posted October 31, 2008 at 9:25 am | Permalink

    Hi Wiep! Thankyou – tat worked a charm. See you at SMX?

  3. Posted October 31, 2008 at 10:49 am | Permalink

    Definitely ;)

  4. Posted December 31, 2009 at 6:44 pm | Permalink

    I have worked on sites before using the loop and coding this action myself, but your code is terrific and so easy.

    I am building a widgetized sidebar for a customer using your code in the text-widgets, press releases, updates and more. Thanks so much!

  5. Posted March 6, 2010 at 12:05 pm | Permalink

    gr8 help thanks for solutions…

Tagged as: