Single Post PER Category on Index (7 posts)

  1. codewarrior
    Posted 10 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
    Posted 10 years ago #

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

  3. Alex Mills (Viper007Bond)
    Posted 10 years ago #

    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
    Posted 10 years ago #

    Here's similar solution.

    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. Alex Mills (Viper007Bond)
    Posted 10 years ago #

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

  6. seg
    Posted 10 years ago #

    I found a similar method to alphaoide's example:


    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.


  7. Alex Mills (Viper007Bond)
    Posted 10 years ago #

    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