Conditional: if in_category

Fundamental 175 views
+1
0 Flares 0 Flares ×

This snippet goes inside the post query and allows you to add code based on the category the post is within.

<?php 
if ( in_category( 'pachyderms' )) {
	// They have long trunks...
} elseif ( in_category( array( 'Tropical Birds', 'small-mammals' ) )) {
	// They are warm-blooded...
} else {
	// & c.
}
?>

For Reference

Function Reference: is_category
Conditional Tags

Tagged with:
Posted in Wordpress

Discuss:

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

No Trackbacks.

Login

Register | Lost your password?
0 Flares Twitter 0 Facebook 0 Google+ 0 0 Flares ×