The MU forums have moved to

Conditional code in sidebar based on category_id (3 posts)

  1. pschena
    Posted 13 years ago #

    Trying to do what I thought would be pretty simple.
    Wanted to add some conditional code based on the post category to the sidebar.

    Code I am using is:

    <?php global $category_id;
    if ($category_id == 259) {echo 'YYY'; }
    else {echo 'NNN'; }; ?>

    Does not seem to be working correctly.
    Not sure where I am going wrong.
    Anyone see what I'm missing?

  2. Driftless1
    Posted 13 years ago #

    Not sure that you've actually got anything in your variable $category_id

    Try using the is_category() function inside a loop... or in_category()

    <?php if (in_category('259')
        echo 'YYY';
        echo 'NNN';

  3. pschena
    Posted 13 years ago #

    Thanks Driftless1.

    Ended up with a plugin work around.
    I think the problem was that it wasn't in the loop.

    // closed

About this Topic