Title: Sub page problem
Last modified: August 19, 2016

---

# Sub page problem

 *  [alst](https://wordpress.org/support/users/alst/)
 * (@alst)
 * [17 years, 9 months ago](https://wordpress.org/support/topic/sub-page-problem/)
 * Hi there,
 * I want to do the following,
 * if a user clicks on a page that is a sub-page of a top level parent page, then
   page.php should call a certain header. If the parent page is different then a
   different header is called.
    There are only two top level pages that I want this
   to happen on, so using the code from the codex page I tried this,
 *     ```
       <?php
   
       if 	(is_page() || $post->post_parent=="65") {
       	$subpagefix="/header-resources.php";
       } elseif (is_page() || $post->post_parent=="221") {
       	$subpagefix="/header-quickref.php";
       } else {
       	$subpagefix="/header.php" ; // Fall-through
       }	
   
       ?>
       <?php include (TEMPLATEPATH . $subpagefix ); ?>
       ```
   
 * So this seems to work for the page 65, but subpages of page 221 call the header-
   resources.php.
 * What have i done wrong?

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Thread Starter [alst](https://wordpress.org/support/users/alst/)
 * (@alst)
 * [17 years, 9 months ago](https://wordpress.org/support/topic/sub-page-problem/#post-844859)
 * Fixed it,
 * the key was removing the “” around the page number.
 * This code works now,
 *     ```
       <?php
   
       if 	(is_page() || $post->post_parent==65) {
       	$subpagefix="/header-resources.php";
       } elseif (is_page() || $post->post_parent==221) {
       	$subpagefix="/header-quickref.php";
       } else {
       	$subpagefix="/header.php" ; // Fall-through
       }	
   
       ?>
       <?php include (TEMPLATEPATH . $subpagefix ); ?>
       ```
   
 *  [zartgesotten](https://wordpress.org/support/users/wearitwell/)
 * (@wearitwell)
 * [17 years, 9 months ago](https://wordpress.org/support/topic/sub-page-problem/#post-844861)
 * I use the [ClassyBody](http://www.alistercameron.com/etcetera) Plugin to display
   different Headers or styles … You only have to insert this piece of code into
   your template (for the body-tag)
 *     ```
       <?php if(function_exists('classybody')) {?>
       <body class="<?php classybody(); ?>">
       <?php } else { ?>
       <body>
       <?php } ?>
       ```
   
 * And in the page you want to display differently you add a custom field named 
   classybody and give it a name.. e.g. “blue”
 * Then you only have to edit you style.css like that…
 *     ```
       body.blue header{
       	color: #blue;
               other syles blah blah;
       }
       ```
   
 * This allows you to create as many different styles as you like!!!
    Maybe this
   helps… cheers wearitwell
 *  Thread Starter [alst](https://wordpress.org/support/users/alst/)
 * (@alst)
 * [17 years, 9 months ago](https://wordpress.org/support/topic/sub-page-problem/#post-844915)
 * This is the definitive fix which allows sub-sub pages to also call the right 
   header.
 * Makes use of the fold_page_list plugin.
 *     ```
       <?php
       //this code uses fold_page_list plugin to generate array of ancestor pages and sets grandparent as top level page
       $g_page_id = $wp_query->get_queried_object_id();
       $ancestorIDs = _wswwpx_page_get_ancestor_ids($g_page_id);
       $grandParent = $ancestorIDs[1];
   
       ?>
       <?php
       //this code keeps lavalamp on the correct parent page when viewing a subpage, add elseif for other top level pages as appropriate
       if      ($grandParent==65) {
               $subpagefix="/header-resources.php";
       } elseif ($grandParent==221) {
               $subpagefix="/header-quickref.php";
       }
       else  $subpagefix="/header.php"
   
       ?>
   
       <?php  include (TEMPLATEPATH . $subpagefix);  ?>
       ```
   

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Sub page problem’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [alst](https://wordpress.org/support/users/alst/)
 * Last activity: [17 years, 9 months ago](https://wordpress.org/support/topic/sub-page-problem/#post-844915)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
