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 this php code that allows me to call a div in different post type, but the only problem is when i add a second line instead of it showing only on the post type page it shows on the home page as well.

When it's only one line it works but when i added the second line the div shows on the homepage as well and i don't want it to show on the homepage at all, how do i fix this.

Here is the code below.

<?php
if (get_post_type() == 'pretty-little-liars') {  echo '<div id="headerimg"><img  src="http://tv-cafe.com/wp-content/uploads/2012/08/liars.png"></div>'; 
} 
?>

and here is what i tried to do

 <?php
if (get_post_type() == 'pretty-little-liars') {  echo '<div id="headerimg"><img  src="http://tv-cafe.com/wp-content/uploads/2012/08/liars.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>'; 
} 
?>

I even tried it with the 'else' function, and it still showed on the homepage.

I placed this in my header file.

The way i have everything coded is that every post type has it's own stylesheet but the same header. But the code above calls for a div which will feature different images above for each post type.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

just use the code below

<?php
if ( ! is_home() ) {

    if ( get_post_type() == 'pretty-little-liars' ) {
        echo '<div id="headerimg"><img  src="http://tv-cafe.com/wp-content/uploads/2012/08/liars.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>';
    }
}
share|improve this answer
    
Thanks but you forgot the closing bracket for the first line :) once you edit it i will vote your answer up :) –  Terrell Anderson Aug 3 '12 at 5:31
    
@Terrell your edit didn't make sense to me. For condition to work things should be inside its brackets as they currently are (and they are correctly opened closed as well from what I see). –  Rarst Aug 3 '12 at 6:17
    
I placed the code in just as is, but that gave my whole site a syntax error, but after i placed the bracket '}' after the first bracket '{'my site was back up and running and working just how i wanted :) –  Terrell Anderson Aug 3 '12 at 7:19

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.