• depruett

    (@depruett)


    I’ve been researching this for four or five days, but haven’t been able to come up with a workable solution, and I’ve gotten to the point where I can’t wrap my head around it anymore.

    On my main page (or a new page that I assign as my home page) I would like to display a specific category name, and then an excerpt of the most recent post for that category (including the post thumbnail).

    Then I would like to follow that with another category title, and a single except of the most recent post for that category – and so on, for a total of 4 or 5 categories.

    Some posts might be in more than one category, so I would need to avoid repetition of those posts.

    That’s the basics of what I need to do. Ideally, I would also like to substitute an image for the category title, and insert a rule between each category/excerpt set.

    This would be replacing the loop on the main page template or on a new page template.

    I’ve experimented with multiple loops, but I’m far from an expert with PHP, so nothing I’ve done has worked.

    Any help would be greatly appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
  • deepbevel

    (@deepbevel)

    This should work for you:

    <h3><a href="url-to-your-category-page">Category 1</a></h3>
    
    <?php query_posts( array('posts_per_page' => 1,  'cat' => '1', ));
    while ( have_posts() ) : the_post();?>
    
    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    <?php the_excerpt(); ?>
    
    <?php endwhile;?>
    <?php wp_reset_query();?>

    You can use this multiple times, but keep it out of the main loop.. put either before “if have posts..ect”
    or after “endif” in your template.

    Thread Starter depruett

    (@depruett)

    That worked perfectly! I tweaked a little bit to style the output, and it’s exactly what I was looking for.

    Thanks so much!

    The only thing I noticed is that I don’t see any code that prevents duplication of posts in the event that one post shares two of the featured categories.

    If there’s a way to do that, that would be awesome, but otherwise I won’t even worry about it.

    Again, thanks so much, I really appreciate it.

    David

    deepbevel

    (@deepbevel)

    that’s great, glad to help.

    look at #10 in this artical:
    wordpress-queryposts-tips

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display a list of category titles, with excerpt of most recent post for each’ is closed to new replies.