try conditional tags
<?php if(is_category('9')) { $class='photo'; } ?>
<li data-id="id-1" class="<?php echo $class; ?>">
If the category ID of your photo category is 9.
thank you keesiemeijer, but i have 5 class i have to write else if for them or switch case?
how to manage them? i have 5 different category for post
you can do it 5 times like so
<?php
if(is_category('9')) { $class='photo'; }
if(is_category('6')) { $class='web'; }
if(is_category('8')) { $class='news'; }
if(is_category('12')) { $class='etc'; }
if(is_category('17')) { $class='whatever'; }
?>
<li data-id="id-1" class="<?php echo $class; ?>">
tnx a lot i am trying now
in output class is empty π it doesn’t work π
<?php if(is_category('5')) { $class='web'; }
if(is_category('7')) { $class='video'; }
if(is_category('8')) { $class='graphic'; }
if(is_category('6')) { $class='photo'; }
if(is_category('9')) { $class='commerce'; }
if(is_category('10')) { $class='coding'; }
?>
<li data-id="id-1" class="<?php echo $class; ?>">
this is all the code for loop
<!-- Begin loop porfolio -->
<?php query_posts('cat=4'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php if(is_category('5')) { $class='web'; }
if(is_category('7')) { $class='video'; }
if(is_category('8')) { $class='graphic'; }
if(is_category('6')) { $class='photo'; }
if(is_category('9')) { $class='commerce'; }
if(is_category('10')) { $class='coding'; }
?>
<li data-id="id-1" class="<?php echo $class; ?>">
<span class="boxgrid caption">
<!-- Begin Full Size Link and Description -->
<a href="<?php bloginfo('stylesheet_directory') ?>/style/images/1.jpg" class="colorbox" title="<?php the_title(); ?>">
<img src="<?php bloginfo('stylesheet_directory') ?>/style/images/th1.jpg"/><!-- Image Thumnail -->
</a>
<!-- End Full Size Link and Description -->
<!-- Begin Caption -->
<span class="cover boxcaption">
<strong><?php the_title(); ?></strong>
<em><a href="<?php the_permalink(); ?>">Click here to visit the details.</a></em>
</span><!-- End Caption -->
</span>
</li>
<?php endwhile; else: ?>
<p>error</p>
<?php endif; ?>
<!-- End loop porfolio -->
In this loop you query the loop for category 4 so you don’t have to test for the category. Or put this in there:
if(is_category('4')) { $class='porfolio'; }
right , my main category is portfolio with id 4 and i need to make query just for this category, and those number are id of sub-category.
shall i change the number of sub-category to name or something else :(?
now class change to “portfolio” the main cat it means it works but how to manage them using with sub-cat?
try this.
change this:
<?php if(is_category('5')) { $class='web'; }
if(is_category('7')) { $class='video'; }
if(is_category('8')) { $class='graphic'; }
if(is_category('6')) { $class='photo'; }
if(is_category('9')) { $class='commerce'; }
if(is_category('10')) { $class='coding'; }
?>
<li data-id="id-1" class="<?php echo $class; ?>">
to only this: <li data-id="id-1" <?php post_class(); ?>>
now you get something like this: <li data-id="id-1" class="category-photo">
if the post has the category photo