Support » How-To and Troubleshooting » Assigning div ids to pages and their children

Assigning div ids to pages and their children

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • @mercime


    Volunteer Moderator

    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.

    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?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Assigning div ids to pages and their children’ is closed to new replies.