Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

IF Category ID, (on Single.php) WordPress


<strong>Admittedly, I have no idea what I'm doing....</strong>

I just need it to check which category the post is in, then display it's respective heading image.

if get_the_category($post->ID) = 6 ) {

echo '<img src="cat-6-heading.jpg" height="60" width="740" border="0"/></div>';

} elseif ( get_the_category($post->ID) = 11 ) ) {

echo '<img src="cat-11-heading.jpg" height="60" width="740" border="0"/></div>';


Answers (2)


Pippin Williamson answers:

use [[LINK href=""]]in_category()[[/LINK]]

if(in_category(6) {
// image here
} elseif (in_category(11)) {
// other image here

Josh Adams comments:

Omg it works. <3


Hameedullah Khan answers:

If your post only has one category then use the following.

$category = get_the_category($post->ID)
echo '<img src="cat-' . $category[0]->cat_ID . '-heading.jpg" height="60" width="740" border="0"/></div>';