[resolved] Dynamic Body ID tags by category name (2 posts)

  1. pshero
    Posted 6 years ago #

    I'm wondering if any of you PHP gurus can help me out. I've gone round and round on this with no success, likely because my php syntax is crap.

    I'm trying to set a body tag id that corresponds to the category the post being displayed belongs to (so I can style that navigation element differently). I can achieve the effect I want by using a if/else if type statement like this:

    <body <?php if (is_home()) { ?>id="home"<?php } elseif (in_category('Photo Effects')) { ?>id="photo-effects"<? } else { ?>id="other"<?php } ?>>

    but what I'd really like to do is call the category the post belongs to dynamically and give the id the name (or just the id number) of the category without all the elseif nonsense.

    I'm thinking it would look something like this:

    <body <?php if (is_home()) { ?>id="home"<?php } else { ?>
    id="<?php echo $cateory->category_name; ?>"<?php } ?>>

    But for some reason that last bit of code doesn't work.

  2. kvcrawford
    Posted 6 years ago #

    So were you able to resolve this? Could you post your solution? I've been trying to figure it out.


Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.