And header-header2.php exists in the theme directory?
Is it merely a modified version of the original header file and does it contain the necessary hooks from the original, just so everything loads okay?
Yeah, header-header2.php is fine. I have called it up with “is_tax” and on a custom page template.
It even works as printed above, the only problem is that it shows up on ALL of my custom post type single posts instead of just the category that I specified.
If there is a better way to call header-header2.php to certain single custom post type posts (like a custom template or something), I’m open to it, although being able to specify it by category (and its children) would be optimal for me.
Do you have any code before term_exists(71), or have you ever got this condition to evaluate to true?
Admittedly I’ve never used terms to determine the header a theme uses, so all of this is speculative.
http://codex.wordpress.org/Function_Reference/get_term
http://codex.wordpress.org/Function_Reference/get_term_by
Are you able to get the term via the functions above in order to somehow get your if statement to evaluate to true?
No code before the term_exists line.
If I put a false value in the (), it retrieves my normal header. But like I said, when I set it to the correct ID, it puts the new header on all single posts of the custom post type. Odd.
Same happened when I used “get_term”.
If terms aren’t the way to go, any other idea how to call header-header2.php in a certain category and its children in a custom post type single post?
Thank you for your help.
Right,
I’ve used something similar to determine parent/child categories.
I use this custom function (in functions.php):
function post_is_in_descendant_category( $cats, $_post = null )
{
foreach ( (array) $cats as $cat ) {
// get_term_children() accepts integer ID only
$descendants = get_term_children( (int) $cat, 'category');
if ( $descendants && in_category( $descendants, $_post ) )
return true;
}
return false;
}
So you could try the following using the above:
<?php if ( is_category('<NAME OF CATEGORY>') || post_is_in_descendant_category(get_cat_id('<NAME OF PARENT CATEGORY>'))) {
get_header('header2');
} else {
session_start(); get_header();
}?>
<NAME OF CATEGORY> and <NAME OF PARENT CATEGORY> are replaced with your category slugs respectively.
Hope that is a step closer to resolving it or helping you out.
Thank you again, Harmck, but it still doesn’t work.
I actually tried that before (and just retried it, copying and pasting your code). I even tried using “in_category” as well as trying “is_category”.
Anyway, I’m pretty sure that those functions don’t work on the custom post types. At least that’s what I have gathered so far.
But thank you again for your help!
Is it something to do with the Loop, and the fact it can’t tell what page/post you’re viewing before it gets to the declaration of the header.
Could you declare something like before your header if statement so as to access the post info?:
global $post;
No, it didn’t work. But thank you again.
The only things I have used that get a response are “term_exists” and “get_terms”, but as I said, then the new header shows up on every custom post type post instead of just the category I identified.
To troubleshoot, I tested by putting in a false category. Nothing showed up. So calling the category is working, it just isn’t limiting itself… If that makes any sense.