WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] a way to set an id on the body tag (in header.php) (6 posts)

  1. syncbox
    Member
    Posted 8 years ago #

    I'm just starting to learn wordpress, php etc, so please be gentle and assume I know nada, especially about using wordpress.

    I am, however, pretty expert with xhtml and css. I'm trying to rebuild my site using wp. My site is css-layout, very few graphics, etc.

    I really need to know how I can dynamically set the body tag's id.

    In a site where elements are part of includes, I can just change the body tag's id. But, of course, my body tag is now a part of my header.php and I cannot make individual changes. I'm not worried too much about all the page, just some of them - like home, about (Pages)

    The only solution I see is to modify the header.php to stop just before the body, and put that tag into the index.php, page.php, home.php files and make separate ones for each "section" or individual "static" Page.

    Does that sound correct? (I hate to as I just got my layout working finally!)

    Or, should I set up all the pertinent links in a file, include it, and make different versions to include that would incorporate the "selected" id on the particular link so that it uses the selected style?

    All in all, neither idea sound all that efficient. Is there another way to just somehow pass a parameter that sets the body tag's id? <body id="">

    Does anyone have other ideas?

  2. makemead
    Member
    Posted 8 years ago #

    There is only one body tag per page, right? Do you need this for CSS or DOM?

  3. syncbox
    Member
    Posted 8 years ago #

    for css. typically, if you are building pages using ssi, you can modify the body tag-- by setting the id, you can tap into css rules that only apply if/when a certain combination of body container settings are met, as in

    body#who div#mainnavs a.who,
    body#home div#mainnavs a.home,
    blah,
    blah

    so that ONLY when the body has a particular id does that rule's property kick in.

    But I decided to move on anyway, and opted to modify the header to separate the navs out of that file so that I can make separate files for a group of templates.

    probably not the most efficient way to do it, but I have to try to finish this by the end of the weekend.

    However, if you have ideas, I'm all ears as I would love to learn a method for the future. I'm like wordpress and hope to take it to my clients wherever possible. I have a big project coming up that I think would be perfect for wordpress.

  4. syncbox
    Member
    Posted 8 years ago #

    OK< I just went back and made the body tag accessible in my templates. Now, I'll set up my group bodyid rules. The beauty of this is that I can control all the properties in any page by setting a class (or multiple classes) and an ID on the body tag to determine background images used in any container, to set the "selected" state of any navigational link, etc.

    When I am done, I'll post a link to my site (content isn't finished by any means, but to show the way css can be controlled via the body tag)

  5. syncbox
    Member
    Posted 8 years ago #

    OK, while reading through the documentation, I think my answer is
    1) make the body tag accessible (which I've done)
    2) build a template for each category (I'm using 3) that will have ongoing posts
    3) build WP Pages for non-post "pages" that equate to static pages

    but, if there is a way to pass an id to the body tag that someone knows about that doesn't involve what I've described, again, I am all ears!

    Donna

  6. syncbox
    Member
    Posted 8 years ago #

    OK, I can mark this resolved as I found the answer to mark the current navigation dynamically.

    http://codex.wordpress.org/Dynamic_Menu_Highlighting

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags