WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a function that will let me display a category title and the last 5 post titles from that category just below it? Is there a loop which can do this and list post titles of that category in an un ordered list with the category title just above outside the loop?

share|improve this question
up vote 0 down vote accepted

you haven't stated where the category id will come from, nor how you want to style the category title, and if the post titles are supposed to be linked to the single post; therefore just the basic structure:

$cat_id = 137; 
    echo '<div class="category-title">'.get_category($cat_id)->name.'</div>;
    $cat_posts = get_posts(array('category__in' => array($cat_id), 'posts_per_page' =>5));
    if($cat_posts) {
        echo '<ul class="category-posts">';
        foreach($cat_posts as $cat_post) {
            echo '<li class="category-post">'.get_the_title($cat_post->ID).'</li>';
        echo '</ul>';
share|improve this answer
Sorry I didn't specify where i'd get the cat ID, I figured i'd hard code the category ID as you showed. For styling I can just wrap the echo function in a div and give it a class or ID same with the ul and li tags. Thanks – Anagio Nov 20 '11 at 20:44
answer edited to add a div and some css classes. – Michael Nov 20 '11 at 21:43
Thanks for making the edits I wouldn't have added them like that – Anagio Nov 20 '11 at 23:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.