WordPress.org

Ready to get started?Download WordPress

Forums

Single Post PER Category on Index (7 posts)

  1. codewarrior
    Member
    Posted 8 years ago #

    I spend some time searching and found all kinds of results for showing only a single post or limiting the categories. But I would like to do the following:

    On the index page I would like to see displayed the most recent post per category only. So I am not limiting the number of posts or number of categories, but show one post only for each category. The number of posts will be driven by the number of categories.

    Any ideas?

  2. seg
    Member
    Posted 8 years ago #

    I am looking to do the same thing - did you resolve this issue?

  3. The problem is that the post details and what category a post is in is stored in seperate tables. Therefore, a simple query just can't be done.

    If you guys REALLY want this, I guess I or someone else could try to throw some code together. It won't be pretty though.

  4. Joshua Sigar
    Member
    Posted 8 years ago #

    Here's similar solution.
    http://rhymedcode.net/1001-wordpression-loops/grouped-by-category/

    Note that in the example above, you have to create a Loop for each category.

    If you add/remove a category frequently, then you need to develop code that will grab all categories.

  5. Meh, there's a much better way to do it. I'll post some code in a bit.

  6. seg
    Member
    Posted 8 years ago #

    I found a similar method to alphaoide's example:

    http://dev.wp-plugins.org/wiki/ShowCats

    This will show the first post (or however many posts assigned in code) for each category - the categories being in a certain order. This is a good fix for the time being.

    Ultimately it would be nice to show the first post for each category organized by most recent post (not by category).

    For example:

    Category 2
    9/20/05 - 4:35 p.m.

    Category 1
    9/20/05 - 3:50 p.m.

    Category 3
    9/19/05 - 6:05 p.m.

    Viper007Bond, I am interested in seeing your idea.

    Thanks!

  7. Yeah, I can get the ID of the first post to each category, but I'm having issues getting the last post.

    SELECT * FROM wp_post2cat GROUP BY category_id ORDER BY post_id DESC

Topic Closed

This topic has been closed to new replies.

About this Topic