Diferent images in header with php
-
I would want three diferent header images in my blog. And I wrote an archive with this function:
<?php if (is_home()) { $logoimg="[...]/images/img1.jpg"; } elseif (is_page()) { $logoimg="[...]/images/img1.jpg"; } elseif (in_category('1')) { $logoimg="[...]/images/img2.jpg"; } elseif (in_category('8')) { $logoimg="[...]/images/img3.jpg"; } elseif (is_archive()) { $logoimg="[...]/images/img1.jpg"; } else { $logoimg="[...]/images/img1.jpg"; }?>
And then, the code in my header.php:
<div id="header"> <?php include(TEMPLATEPATH . '/functions.php'); echo "<div id=\"header-img\" style=\"background:url($logoimg) no-repeat bottom right\">" ?> </div> </div>
It works, but in the monthly archives and in the search results, because the image is always the one of the category of the first post that show in the archive or in the search. The problem is I can not change the in_category to is_category, because a have a categories parents and children and then it does not work right.
Does anybody know how could I get the right image in the monthly archives and in the search results? For the moment, I did three diferents headers, but there is no the best solution. Thank you in advance for the help.
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Diferent images in header with php’ is closed to new replies.