<?php
if (in_category(‘1′)) echo “<img src=’/images/teams.jpg’ />”;
elseif (in_category(‘4′)) echo “<img src=’/images/child-sponsorship.jpg’ />”;
else echo “<img src=’/images/home-image.jpg’ />”;?>
I hate using if followed by colons. Hard to read and understand.. Bah. I’m also not a big fan of continually opening and closing the PHP blocks every other line.
Try this instead:
<?php
if (in_category('1')) {
echo "<img src='/images/teams.jpg' />";
}
else if (in_category('4')) {
echo "<img src='/images/child-sponsorship.jpg' />";
}
else {
echo "<img src='/images/home-image.jpg' />";
}
?>
See how much nicer that is? Spaced out, easy to read, groups the bits together naturally… just nicer, IMO. Works too. 🙂
Thread Starter
jefft
(@jefft)
Thanks for all your help! But I’m still having a problem…the home page displays does not display the “else” image, but rather, the image from the corresponding category of the first post. Suggestions?
Thread Starter
jefft
(@jefft)
Not first post, but most recent post. (The first one WP displays.)
jefft: Add an “if (is_home()) { blah blah }” to the beginning of the series of if statements. That way, you can explicitly define what you want on the home page.