Support » Fixing WordPress » Displaying different featured post in category template

  • Hi everyone,
    Here is my problem. I have 5 different categories, displayed in a category template (category.php), with a color by category. I would like to display 1 featured post, for each category. (using the tag “featured”, but if you have a better idea…)
    example :
    “baby” have 1 featured post
    “mom” have 1 featured post

    I use this code (found here)

    <?php
    
    global $wp_query;
    $args = array_merge( $wp_query->query, array( 'post__not_in' => $do_not_duplicate ) );
    query_posts( $args );
    
        $args = array(
                'posts_per_page' => 1,
                'tag' => 'featured',
            );
    
            $featured = new WP_Query($args);
            if($featured->have_posts()): while($featured->have_posts()): $featured->the_post();
                the_title();
    
            endwhile; else:
    
            endif;
        ?>

    I have the same featured post displayed in all categories. How to display each featured post in their current category ?
    Thanks in advance !

  • The topic ‘Displaying different featured post in category template’ is closed to new replies.