JHP
JHP

Reputation: 121

WordPress How To Change My Header Depending On The Category

I am trying to change my header depending on the category. I have tried the id and the slug and for some reason it is not working. There must be something wrong with my method. I am using a if else statement.

if ( is_category('6') ) {
get_header( 'news' );}
else {
get_header();
}

I have also tried:

if ( is_category('news') ) {
get_header( 'news' );}
else {
get_header();
}

My header is named header-news.php I was using the info from this page:

http://codex.wordpress.org/Conditional_Tags#A_Category_Page

Any help would be appreciated.

I am changing the single.php I did first try calling the header-news.php first to make sure it works and it did, my if else statement seems to be wrong.

Upvotes: 1

Views: 1283

Answers (2)

JHP
JHP

Reputation: 121

Ok, so the answer to this is to use: in_category

http://codex.wordpress.org/Template_Tags/in_category

I changed the code to read:

if (in_category( 'news' ) ) {
get_header( 'news' );}
else {
get_header();
}

It worked perfectly!

Upvotes: 2

Aurelia
Aurelia

Reputation: 1062

is_category is intended for archive pages; in_category is for use within the loop.

Upvotes: 1

Related Questions