How to recover the top-level page ancestor slug or ID to use in HTML? (4 posts)

  1. andydarley
    Posted 5 years ago #

    I'm working on a theme where I need to change some header text and an image depending on which part of the hierarchy of static pages the user is on.

    The text needs to be easily editable by the user, so I want to put it in a widget, while the image will be called by HTML rather than as a background image by CSS.

    In both cases I could accomplish this if I could recover some detail of the top level page ancestor, such as its ID or slug, and use it either with .jpg on the end to call an image or in the code used to call a widget.

    But my skills lie towards CSS and design, not PHP - can anyone advise how to do this? I have found the functions.php addition that adds the top level ancestor ID to the body classes, but don't have the knowledge to make it work in the page itself.

    Thanks in advance,

  2. andydarley
    Posted 5 years ago #

    It's OK - I've found a work-around now. Ugly but successful.

  3. Bodhipaksa
    Posted 4 years ago #

    What was your work-around. I'm trying to do the same thing, and have only managed to style parent and child pages, but not grandchild pages.

  4. FutureHasNoBounds
    Posted 4 years ago #

    This come to mind. Put it in page.php.

    <?php if ( is_page ('grandchild_page') ){
    get header('alternate');
    } ?>

Topic Closed

This topic has been closed to new replies.

About this Topic