WordPress.org

Ready to get started?Download WordPress

Forums

Assigning div ids to pages and their children (3 posts)

  1. lycander
    Member
    Posted 5 years ago #

    I've been trying to figure out a way to assign particular header div ids to particular pages. I want my div id to not only be assigned to a particular page, but also to all of its children. In order to assign the div id to a page, I've used the following code:

    <?php if (is_home() ) { ?>
        <div id="header">
    <?php } else { ?>
        <div id="<?php echo $post->post_name; ?>">

    The way it works, then, is that I have a div id with the same name as the page (page name = example, div id entry in CSS = #example). This has been working extremely well.

    My question is, does anyone have a suggestion for how to set it up similarly, but have all of the page's children recall the div id of their parents? (page's parent = example, therefore page's id recalled = #example) I've been trying to do this through using page_parent, but I just simply can't figure it out!

    Thanks so much!

  2. @mercime
    Volunteer Moderator
    Posted 5 years ago #

    Create a page template for each of specific parent and children pages. Call template to be used in parent/children pages in Admin >Write Page and use Page Template dropdown to choose template.
    For other pages without children and without customization, use regular page template.

  3. lycander
    Member
    Posted 5 years ago #

    I thought of that, but the place I'm using the code is within the header.php file within the <head> (to adjust header images, etc.), so I was under the impression that you can't futz with stuff within the header.php from within a page template. Or am I wrong about that?

Topic Closed

This topic has been closed to new replies.

About this Topic