WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How To Change The Header Depending On The Category (3 posts)

  1. Jessica
    Member
    Posted 8 months ago #

    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.

  2. Pioneer Valley Web Design
    Member
    Posted 8 months ago #

    If you want the header to change on a single post page use in_category

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

  3. Jessica
    Member
    Posted 8 months ago #

    Thank you! That was perfect. I changed the code to:

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

    And it worked.
    Yay!

Reply

You must log in to post.

About this Topic