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:

<?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.

Answers


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(); ?>

Need Your Help

Can't figure out how to correctly call an element

javascript jquery html

I have some JQuery that does a ton of stuff with reordering and adding links to the nav, but the important part is that it's supposed to hide every nav link except for the first one (by looping thr...

Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near 'Programming'

sql-server sql-server-2008 c#-4.0

I'm using a button to add product to database when clicking it. this is the code which I written, but it creates an unhandled exception. please help me to correct it...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.