WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to call specific header for child pages of parent? (2 posts)

  1. svsdnb
    Member
    Posted 1 year ago #

    I am designing a custom theme that essentially has 3 site sections.

    MAIN PAGE (header-home.php)

    Secondary Main Page (header-ph.php)

    Third Main Page (header-bh.php)

    Each section will have a dynamic nav in relation to the parent page you're on.

    Right now I can get each Parent page to pull it's respected header however the child pages to each parent pull in the default header.

    Here is my code.

    MyHome.php
    <?php get_header ('home'); ?>

    PublicHealth.php
    ?php get_header('publichealth'); ?>

    PublicHealth.php template is called to the Public Health parent page. I then created subpages (child pages) from this parent. However the header resorts to the 'home' header vs the 'publichealth' header.

    What sort of conditional code do I need in here to make this happen? I've searched and tried a few suggestions with no luck.

    Thank you,

  2. svsdnb
    Member
    Posted 1 year ago #

    omg. I feel dumb... Next link I found and I got it.

    this worked for me

    <?php

    if (is_page() || $post->post_parent==456) {
    $subpagefix="/header-publichealth.php";
    } elseif (is_page() || $post->post_parent==72) {
    $subpagefix="/header-home.php";
    } else {
    $subpagefix="/header-home.php" ; // Fall-through
    }

    ?>
    <?php include (TEMPLATEPATH . $subpagefix ); ?>

    I just posted this on the page.php file in place of get_header

Topic Closed

This topic has been closed to new replies.

About this Topic