WordPress.org

Forums

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

  1. Minus3
    Member
    Posted 9 years ago #

    Hello,

    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,

    Maarten

  2. moshu
    Member
    Posted 9 years ago #

  3. Ryan Fitzer
    Member
    Posted 9 years ago #

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

    http://wordpress.org/support/topic/76805?replies=5

    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.

    http://wordpress.org/support/topic/50315/page/2?replies=35#post-398325

  4. Minus3
    Member
    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) :
    the_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.

    Maarten

  5. Aleister
    Member
    Posted 8 years ago #

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

    http://www.dagondesign.com/articles/latest-post-from-each-category-plugin-for-wordpress/

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.