LZ1
asked on
Wordpress Conditional Statement
Hey Experts!!
I'm trying to incorporate some primitive functionality on my WordPress blog. Basically I want to show a certain image based on the 2nd cat_ID in the $category array. Problem is, it's not working.
I can echo the ID I need, but my else/if isn't doing what I think it should be doing.
Any help is appreciated!
I'm trying to incorporate some primitive functionality on my WordPress blog. Basically I want to show a certain image based on the 2nd cat_ID in the $category array. Problem is, it's not working.
I can echo the ID I need, but my else/if isn't doing what I think it should be doing.
Any help is appreciated!
<?php
if($category[1]->cat_ID == '1116') //skis.com
echo ('<a href="http://mydomain.com/">
<img src="http://content-1.s3.amazonaws.com/images/skis/tag-cloud.jpg" alt="Save On Packages" title="Save On Packages" width="250px"/>
</a>');
elseif($category[1]->cat_ID == '1452'); //snowboards.net
echo ('Snowboards.net');
?>
//This is my echo and it prints out fine.
$category = get_the_category();
echo $category[1]->cat_ID;
ASKER
@gtagliani: I'm not even getting the image now on the first category.
im sorry u must have the "$category = get_the_category();" before the code.
$category = get_the_category();
if($category[1]->cat_ID == '1116')
{
echo ('<a href="http://mydomain.com/"><img src="http://content-1.s3.amazonaws.com/images/skis/tag-cloud.jpg" alt="Save On Packages" title="Save On Packages" width="250px"/></a>');
}else if($category[1]->cat_ID == '1452'){
echo ('Snowboards.net');
}
is this code on your sidebar.php? wp version?
ASKER
I do, however it's separate from the rest of this PHP code. I have it in it's own block.
Tried the above with no love.
Tried the above with no love.
ASKER
Yep, sidebar.php and WP version 2.8
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
2 things:
1) I realized it's the wrong value.
2) after removing the ; it worked fine.
Thanks!!
1) I realized it's the wrong value.
2) after removing the ; it worked fine.
Thanks!!
Open in new window