• Resolved taghaboy

    (@taghaboy)


    hi,
    i use the condition “if, else” to change the image header of my theme in every category (page & post) with this code:

    <?php if (is_category('movie')) { ?>	<img src="<?php bloginfo('stylesheet_directory'); ?>/cat-banner/movie.jpg" 	alt=""></img>
    <?php } elseif (is_404() ) { ?>	<img src="<?php bloginfo('stylesheet_directory'); ?>/cat-banner/404.jpg" 	alt=""></img>
    <?php } else { ?>			<img src="<?php bloginfo('stylesheet_directory'); ?>/cat-banner/home.jpg" 	alt=""></img>
    <?php } ?>

    My question is: how can i add this line to be global category not only “movie”:

    <img src="<?php foreach((get_the_category()) as $category) { echo get_bloginfo ( 'stylesheet_directory' ) . '/cat-banner/' . $category->cat_name . '.jpg" alt="' . $category->cat_name . '" />'; } ?></img>

    Thanks and hop u understand my question.

    [moderated–bump removed. Please refrain from bumping as per Forum Rules]

Viewing 1 replies (of 1 total)
  • Thread Starter taghaboy

    (@taghaboy)

    resolved; this is the solution :

    <?php if (is_category()) { ?>        <img src="<?php foreach((get_the_category()) as $category) { echo get_bloginfo ( 'stylesheet_directory' ) . '/cat-banner/' . $category->category_nicename . '.jpg" alt="' . $category->cat_name . '" />'; } ?></img>
    <?php } elseif (is_404() ) { ?>     <img src="<?php bloginfo('stylesheet_directory'); ?>/cat-banner/404.jpg"         alt=""></img>
    <?php } else { ?>                   <img src="<?php bloginfo('stylesheet_directory'); ?>/cat-banner/home.jpg"       alt=""></img>
    <?php } ?>

Viewing 1 replies (of 1 total)
  • The topic ‘Help with : if , else.’ is closed to new replies.