in_category
CATEGORY TAG
What It Does
in_category will check to see if the specified post is assigned to any given category. Note that only direct categories will be shown- not parent categories.
For example, if a post resides in News > Technology, the category name “Technology” will be returned.
Categories can be specified by its numerical ID number, its name or its slug. Depending on the usage, in_category can be used within or outside The Loop.
Code
“Category” is required, and specifies which category/categories you want to specify. You can use the category name, slug, or its numerical ID number.
“Post” is optional, and allows you to specify a specific post to query.
Example
There are many creative ways you can use in_category, both inside and outside The Loop. Let’s say you have two different sidebars setup- sidebar1.php and sidebar2.php. If a post resides in the “Technology” category, you want sidebar2 to be used:
include ‘sidebar2.php’;
} else {
include ‘sidebar1.php’;
}
?>




