My overall goal is to be able to show a different image based on a certain category name in Wordpress. I'm hard coding this since we're not allowed to use plugins.(I don't know why).
My code is below. What I've been doing is getting the category array and then if the 2nd iteration of that array(2nd category)is equal to whatever I have set, then show an image. The fundamental flaw with this is that the 2nd iteration of the categories array will not always contain the value I'm searching for.
What I thought I could do is search the array, using array_search, to find the exact name I'm looking for. I just have no idea how to set that up.
Any and all help is appreciated. Code that I have so far is below:
$category = get_the_category($id);
if($category->name == 'name1') //name1
echo ('<a href="http://mydomain.com/">
<img src="goes here" />
elseif($category->name == 'name2') //name2
elseif($category->name == 'name3') //name3
elseif($category->name == 'name4') //name4