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(); ?>
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 addedis_category()
which you would use if you were displaying a category archive;is_category
in_category
The class name is changed appropriately.
I guess you mean in an archive page – in which case, use is_category();
So,