Link to home
Start Free TrialLog in
Avatar of LZ1
LZ1Flag for United States of America

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!
<?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');			
			?>

Open in new window

//This is my echo and it prints out fine.
$category = get_the_category(); 
echo $category[1]->cat_ID;

Open in new window

Avatar of gtagliani
gtagliani

try this code:


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');

}

Open in new window

Avatar of LZ1

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');

}

Open in new window

is this code on your sidebar.php? wp version?
Avatar of LZ1

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.
Avatar of LZ1

ASKER

Yep, sidebar.php and WP version 2.8
ASKER CERTIFIED SOLUTION
Avatar of gtagliani
gtagliani

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of LZ1

ASKER

2 things:
1) I realized it's the wrong value.
2) after removing the ; it worked fine.

Thanks!!