The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

[resolved] Pass global variable to category.php? (2 posts)

  1. plevy
    Posted 5 years ago #

    Hi all,

    I'm trying to set a global variable in header.php that is tested in single.php and category.php.

    Below is the code I'm using. This works on single pages, but it does not work on category pages.

    What am I missing?

    this is in my header.php

    if (in_category( array('cat1','cat2','cat3')) || is_category( array('cat1','cat2','cat3')) || is_page('MyPage')) {
    global $subnav;
    $subnav = "foo";

    this is in both single.php and category.php

    if ($subnav == "foo") {
  2. plevy
    Posted 5 years ago #

    Forget it. I figured out a workaround by moving the conditionals and setting of the global variable into functions.php.

    It also tripped me up that is_archive() returns TRUE for category pages as well.

Topic Closed

This topic has been closed to new replies.

About this Topic