header image by category
-
I am looking at trying to get a different image to show based on the category of the post. I found this bit of code in the forums, but the topic is closed so I can’t really ask questions on that post.
This is the code I found.
<?php /* Calls the header image for each category – necessary code */
$post = $wp_query->post;
if ( in_category(‘3’) ) {
$imgurl = “images/category3.jpg”;
} elseif ( in_category(‘4’) ) {
$imgurl = “images/category4.jpg”;
} elseif ( in_category(‘5’) ) {
$imgurl = “images/category5.jpg”;
} elseif ( in_category(‘8’) ) {
$imgurl = “images/category8.jpg”;
} elseif ( in_category(’13’) ) {
$imgurl = “images/category13.jpg”;
} elseif ( in_category(’15’) ) {
$imgurl = “images/category15.jpg”;
} else {
$imgurl = “images/all.jpg”;
}
?>What I don’t know is how to call the variable $imgurl to display the image.
Here is what I to set up.
<div id=”header”>
<img src=”$imgurl”>
</div>Thanks.
The topic ‘header image by category’ is closed to new replies.