Forums

[resolved] Help with : if , else. (2 posts)

  1. taghaboy
    Member
    Posted 3 years ago #

    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]

  2. taghaboy
    Member
    Posted 3 years ago #

    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 } ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags