WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Child page to show same header as Parent page (4 posts)

  1. cosmic-emma
    Member
    Posted 1 year ago #

    On my website each parent page has a different header. I have been able to generate this successfully by using this code:

    <?php
    $post = $wp_query->post;
    if ( is_page('page1') ) {
    include(TEMPLATEPATH . '/header-1.php');
    }
    ?>

    But when I go to a child page no header is showing.

    What I need is for child pages to show the same header as its parent.

    Any idea?

  2. Rev. Voodoo
    Volunteer Moderator
    Posted 1 year ago #

  3. cosmic-emma
    Member
    Posted 1 year ago #

    Unfortunately, I'm still not getting anywhere.

    Parents have different headers and the child pages need to show their parent's headers - can someone shed some more light on how to do this?

  4. cosmic-emma
    Member
    Posted 1 year ago #

    Okay I got this to work, this maybe the long way of doing things but it does work!

    I have this code in the header.php linking to other specific headers:
    <?php
    $post = $wp_query->post;
    if ( is_page('page1') ) {
    include(TEMPLATEPATH . '/header-1.php');
    }if ( is_page_template('one-page.php') ) {
    include(TEMPLATEPATH . '/header-1.php');
    if ( is_page('page2') ) {
    include(TEMPLATEPATH . '/header-2.php');
    }if ( is_page_template('two-page.php') ) {
    include(TEMPLATEPATH . '/header-2.php');
    }
    ?>

    Each section has it's own page-template which is allowing me to target the child pages with the parent.

    If anyone else has a better way please let me know?

Topic Closed

This topic has been closed to new replies.

About this Topic