Change an image according to categories, pages, single or home
-
Hi!
I want my website to change an image depending on if it′s in a category, a page, etc.
My code is:<?php if (is_front_page() ) { $cat = "home"; } elseif (is_page(array("archives"))) { $cat = "archive"; } elseif (is_page() || is_search()) { $cat = "page"; } elseif (is_category() || is_single()) { $cat = get_the_category(); $cat = $cat[0]->slug; } ?>
<div id="wrapper" class="<?= $cat_title ?> <?php if (is_single()) echo 'post' ?>"> <a href="https://k-i-t.com.ar/"><img src="https://k-i-t.com.ar/wp-content/themes/kit/images/kit-marca-azul-tienda-regalos.png" alt="" width="75" height="41" border="0" style="opacity:0;filter:alpha(opacity=0)"/></a></div>
CSS:
#wrapper.home { position:absolute; width: 75px; height:41px; margin: 55px 0px 0px 0px; background: url(images/kit-marca-azul-tienda-regalos.gif) #FFF; } #wrapper.archive { position:absolute; width: 75px; height:41px; margin: 55px 0px 0px 0px; background: url(images/kit-marca-azul-tienda-regalos.gif) #FFF; } #wrapper.page { position:absolute; width: 75px; height:41px; margin: 55px 0px 0px 0px; background: url(images/kit-marca-verde-tienda-regalos.gif) #FFF; } #wrapper.cuadernos { position:absolute; width: 75px; height:41px; margin: 55px 0px 0px 0px; background: url(images/kit-marca-azul-tienda-regalos.gif) #FFF; } #wrapper.bienvenida { position:absolute; width: 75px; height:41px; margin: 55px 0px 0px 0px; background: url(images/kit-marca-amarillo-tienda-regalos.gif) #FFF; } #wrapper.regalo { position:absolute; width: 75px; height:41px; margin: 55px 0px 0px 0px; background: url(images/kit-marca-naranja-tienda-regalos.gif) #FFF; } #wrapper.cocina { position:absolute; width: 75px; height:41px; margin: 55px 0px 0px 0px; background: url(images/kit-marca-rosa-tienda-regalos.gif) #FFF; }
If it′s home or a page works fine. But I can′t make it work if it′s category or single. It′s important that I can make the code work automatically, so I don′t have to type every category title or single title.
Thanks!!
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Change an image according to categories, pages, single or home’ is closed to new replies.