• I have something like
    < ?php if (is_home()) {
    $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;
    query_posts(“cat=1,2,3&paged=$paged”);
    } ?>

    I would like to make it so that only one post in each of the three categories can show up on the main page. If I use &showposts=3, it will only show me the three recent posts regardless of the category it is in. I would like one post from each category to show up on the homepage. How do I do this?

Viewing 7 replies - 1 through 7 (of 7 total)
  • This tidbit from filosofo (Austin Matzko)

    Latest post from each of six categories, 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' => 1)) ) {
                    $first = array_shift($posts);
                    $post_ids[] = $first->ID;
            }
    }
    query_posts(array('post__in' => $post_ids));

    Thread Starter indiaberry

    (@indiaberry)

    Where should I put that code? It didn’t work where I put it.

    use in place of

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts("cat=1,2,3&paged=$paged");

    Thread Starter indiaberry

    (@indiaberry)

    That doesn’t work because the category that I am trying to exclude are from the homepage are showing up on the homepage. The first two recent posts are in a category that I excluded from the homepage. With that code, the two posts from that exclude category is shown on the homepage.

    Thread Starter indiaberry

    (@indiaberry)

    I am not sure why it doesn’t work. I am using three categories instead of 6, so I put in the correct cat id. Could you help me to make this work?

    Thread Starter indiaberry

    (@indiaberry)

    I was testing out the ‘query-post’ tags. I noticed that anything with array does not work. Do the ‘array’ not work in wordpress 2.0.11?

    Not sure about 2.0.11. Please upgrade.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘one post from three categories on homepage’ is closed to new replies.