Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Hi I'm using the code below to show different header images in my custom template archives.

Only problem is that it is also showing the headers in the category templates.

go to http://tv-cafe.com/category/video that image at the top isn't suppose to be there, how do i get that to not show.

<?php
if ( ! is_home() ) {

if ( get_post_type() == 'pretty-little-liars' ) {
    echo '<div id="headerimg"><img  src="http://tv-cafe.com/wp-content/uploads/2013/01/pllbanner.png"></div>';
}
if ( get_post_type() == 'revenge' ) {
    echo '<div id="headerimg"><img  src="http://tv-cafe.com/wp-content/uploads/2012/08/revenge.png"></div>';
}
if ( get_post_type() == 'grimm' ) {
    echo '<div id="headerimg"><img src="http://tv-cafe.com/wp-content/uploads/2013/01/girmmbanner.png"></div>';
}
}
?>
share|improve this question
    
you can also use this codex.wordpress.org/Function_Reference/is_archive –  Reigel Jan 17 '13 at 9:00
add comment

1 Answer

up vote 0 down vote accepted

You can achieve that by changing the conditional to

if ( !is_home() && !is_archive() )

Also consider using if and else if. So your optimized code would be:

<?php

    if ( !is_home() && !is_archive() ) {

        if ( get_post_type() == 'pretty-little-liars' ) {
            echo '<div id="headerimg"><img  src="http://tv-cafe.com/wp-content/uploads/2013/01/pllbanner.png"></div>';
        } else if ( get_post_type() == 'revenge' ) {
            echo '<div id="headerimg"><img  src="http://tv-cafe.com/wp-content/uploads/2012/08/revenge.png"></div>';
        } else if ( get_post_type() == 'grimm' ) {
            echo '<div id="headerimg"><img src="http://tv-cafe.com/wp-content/uploads/2013/01/girmmbanner.png"></div>';
        }

    }

?>
share|improve this answer
    
Thank you, and instead of placing is_archive, i placed is_category() because my post types have archives that will be using those :) –  Mihad Aiko Jan 17 '13 at 9:18
    
Ok, did not know that :) –  fischi Jan 17 '13 at 9:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.