[resolved] Show latest post per category on homepage (5 posts)

  1. Minus3
    Posted 9 years ago #


    I'm a new WP user and already experienced my first problem, shouldn't sound too new for you. For a website, I only want to show the latest post per category on the homepage. I tried to search on the web and also on this website how to do that, but I can't seem to implement the suggestions I came across properly.

    The method 'query_posts' doesn't seem to do what I want to accomplish since it seems to apply to all posts, not per category. I also tried a few plugins, including Matt Read's 'Custom Query String 2.7', but that one doesn't work for me on the homepage, only on category pages.

    Could someone please point me to the right direction? I'm suspecting I should be able to pull it off with CQS (because of this post) but it seems as if I can only define a maximum for my home page or a category page, not a for a category on the home page.

    Many thanks in advance,


  2. moshu
    Posted 9 years ago #

  3. Ryan Fitzer
    Posted 9 years ago #

    This might help. I think I had the same problem as you.


    This gives you a double loop on the front page that shows two posts from category 1 and from category 2. Of course you can change which categories are shown. I'm not sure how many loops you can put on a page, I've only tried two.

    Here'something I use in the sidebar to show just the most recent titles of specific categories.


  4. Minus3
    Posted 9 years ago #

    See if this thread helps: [...]

    Thanks, moshu. To put it in a Dutch way, yesterday I couldn't see the trees through the forest no longer - I found too many different solutions and wasn't sure which method would be the correct one, but Kafkaesqui's code was very easy for me to implement and modify.

    For those who are interested what I changed, almost nothing.

    foreach($posts as $post) :
    $category = get_the_category();
    if($current_cat == $category[0]->cat_ID) :
    display post here....
    break; // break out of this loop after having displayed the first post
    endif; // end 'if post in correct category'
    endforeach; // end post loop

    And since the posts are ordered chronologically by default, that break was all I had to add to make it work the way I want.

    And ryanfitzer, thanks for the reply anyway.


  5. Aleister
    Posted 9 years ago #

    I know this is resolved, but I thought I would share my plugin anyway which does exactly this:


Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.