Different loop for posts in a special category

I’m using WordPress and I want to use a different loop for posts that are in the category “Streetstyle”. So, for example if there is a post categorized in “Photography” the styling of the loop will be normal. But if the post are categorized in “Streetstyle”, there will be a black border around the post.

This is my loop:

Read More
<?php query_posts('posts_per_page=9' . '&orderby=date'); 
        while ( have_posts() ) : the_post(); ?>         
            <div <?php post_class('pin'); ?>>
                <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
                <?php if ( has_post_thumbnail() ) {
                    the_post_thumbnail();
                } 
                the_content('Les mer'); ?> 
            </div>

        <?php endwhile;
        // Reset Query
        wp_reset_query(); ?>

Live preview here.

Related posts

Leave a Reply

2 comments

  1. In your question you talk about using a different loop but I’m thinking based on what you’ve said and the link that it’s actually the same loop you’d use, and you would just add some conditional code to check whether the post was in the Streetstyle category.

    The code below does that, it checks if the post is in_category() and I’ve also added is_category() which you would use if you were displaying a category archive;

    is_category

    in_category

    The class name is changed appropriately.

    <?php query_posts('posts_per_page=9' . '&orderby=date'); 
        while ( have_posts() ) : the_post();  
            if (is_category( 'Streetstyle' ) || in_category( 'Streetstyle' ) ) ?>
                <div <?php post_class('pin'); ?>>
            <?php } else { ?>   
                <div <?php post_class('pin-blackborder'); ?>>
            <?php } ?>  
                    <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
                    <?php if ( has_post_thumbnail() ) {
                        the_post_thumbnail();
                    } 
                    the_content('Les mer'); ?> 
                </div>
    
        <?php endwhile;
        // Reset Query
        wp_reset_query(); ?>