WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Dynamic Body ID tags by category name

[Resolved] Dynamic Body ID tags by category name

  • 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.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘[Resolved] Dynamic Body ID tags by category name’ is closed to new replies.
Skip to toolbar