• andydarley

    (@andydarley)


    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,
    Andy

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter andydarley

    (@andydarley)

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

    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.

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

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

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to recover the top-level page ancestor slug or ID to use in HTML?’ is closed to new replies.