WordPress.org

Ready to get started?Download WordPress

Forums

Top-most Parent Category Name (2 posts)

  1. qrayg
    Member
    Posted 7 years ago #

    I want to have a universal body tag that gets assigned a unique id based on the top-most parent category of the current view, whether it be single post, archive, category, whatever. I basically want to do dynamic highlighting on the nav but without all that php. It could be done easier in CSS if I could just get the parent category name on every page.

    Is this possible in WP?

    Example: I have a shared header file that gets called on every page view. Inside that header file is a body tag like so:

    <body id="sect-<?php the_parent_category(); ?>">

    I want something equivalent to <?php the_parent_category(); ?>.

    Then in my CSS I define the nav states depending on that id in the body. The site will only have 4 or 5 main nav points so the CSS could be very clean and would force the browser to render the nav state rather than pushing it onto the server like the PHP method.

    Can anyone help me with this? Thank you.

  2. josefdunne
    Member
    Posted 6 years ago #

    This is something I am looking for also! Does anyone have any ideas?

    Thanks

    Josef

Topic Closed

This topic has been closed to new replies.

About this Topic