WordPress.org

Forums

conditional headers (5 posts)

  1. mvincentmiller
    Member
    Posted 3 years ago #

    if ( is_page('5') ) :
      get_header();
    elseif ( in_category('5') ) :
    get_header('wisdom');
      else :
      get_header('home');
    endif;

    Is_category and in_category do not work, however is_page does (at the line where is_category is). I would prefer to use this method if possible, but I have looked at the body class method.

    Thank you.

  2. alchymyth
    Forum Moderator
    Posted 3 years ago #

    is_category() should work in category archives, while in_category() might not work outside of single posts or outside the loop.

    http://codex.wordpress.org/Function_Reference/in_category
    http://codex.wordpress.org/Function_Reference/is_category

    you might need to describe in words when you want which header to show, to get more suggestions.

  3. mvincentmiller
    Member
    Posted 3 years ago #

    This code is located in the page.php file, which may be part of the problem. I am calling different headers for different pages and categories. The problem is, is_page will work, whereas is_category and in_category will not.

  4. alchymyth
    Forum Moderator
    Posted 3 years ago #

    This code is located in the page.php file, which may be part of the problem

    yes.

    there is no category info available in page.php (which is the template for static pages only).

  5. mvincentmiller
    Member
    Posted 3 years ago #

    Is there a place I should put it instead? Speaking of static pages, I've reverted to static HTML as the deadline is looming, the plan being to use three separate blogs (there are three individual authors) instead.

Topic Closed

This topic has been closed to new replies.

About this Topic