Support » Fixing WordPress » Display one post per category

  • I am trying to figure out a way to display 3 of the latest post from 8 categories. I need only show 1 post from each category so if cat1 has 3 post that are newer than the other categories I still only want to display one of them.

    Breakdown: Page that displays 3 of the latest post from 8 categories. Doesn’t matter which category post is not displayed due to it being limited to displaying 3, just cant show more that 1 per category.

    I cant figure out logically how to do this. Any ideas?

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • esmi

    (@esmi)

    Forum Moderator

    Austin Matzko put this on the wp-hackers list some time back…
    ————————-
    Latest post from each of six categories
    I would do something like this, where 1-6 are the category ids:

    $post_ids = array(0);
    foreach( array(1, 2, 3, 4, 5, 6) as $cat_id ) {
            if ( $posts = get_posts(array('cat' => $cat_id, 'showposts' => 5)) ) {
                    $first = array_shift($posts);
                    $post_ids[] = $first->ID;
            }
    }
    query_posts(array('post__in' => $post_ids));

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Display one post per category’ is closed to new replies.