Search code examples
phphtmlwordpresscustom-wordpress-pages

Conditional Tags for Custom Post Types


I've just started using a custom post type for my site, and on some pages within this custom post type, for example:

/custom/post-one /custom/post-three

I want to show some different content in the header. This is easy to do for pages like:

if (is_page(array('page-here','page-here','page-here','page-here'))) {
include(TEMPLATEPATH.'/header-red.php');
} 
elseif (is_page(array('page-here','page-here','page-here','page-here'))) {
include(TEMPLATEPATH.'/header-blue.php');
}
elseif (is_page(array('page-here'))) {
include(TEMPLATEPATH.'/header-green.php');
}  
else {
get_header();
}

How would I go about converting the above script I use for normal pages, to work on my custom post type pages?


Solution

  • I have now achieved this by using the Post ID as below:

    if ( get_the_ID() == 4915 ) {
    include(TEMPLATEPATH.'/header-red.php');
    } 
    elseif ( get_the_ID() == 7564 ) {
    include(TEMPLATEPATH.'/header-blue.php');
    }
    elseif ( get_the_ID() == 71564 ) {
    include(TEMPLATEPATH.'/header-green.php');
    }  
    else {
    get_header();
    }