• I am trying to test for the child of a page. I have tried using this function found on the internet

    function is_child($pageID) {
    	global $post;
    	if( is_page() && ($post->post_parent==$pageID) ) {
                   return true;
    	} else {
                   return false;
    	}
    }

    in the functions.php file …but to no avail.
    My problem is simple; if the page is a child of another page, do this, elseif, etc..
    I have this conditional statement in my header.php so that when any child of a main page is clicked on, the submenu under the main “Image/Title” area stays consistent. Here’s the code:

    <?php if (is_page(13) || is_child(13) ) : ?>
    
    <div class="subMenuContainer">
    <?php	wp_nav_menu( array( 'items_wrap' => '%3$s', 'container_class' => 'subMenu', 'after' => '<li class="menu-divider">|',  'theme_location' => 'sectors' ) ); ?>
    </div><!-- end subMenuContainer -->
    
    <?php  elseif ( is_page(11) ||  is_child(11) ) : ?>
    
    <div class="subMenuContainer">
    <?php	wp_nav_menu( array( 'items_wrap' => '%3$s', 'container_class' => 'subMenu', 'after' => '<li class="menu-divider">|', 'theme_location' => 'services' ) ); ?>
    </div><!-- end subMenuContainer -->
    
    <?php  elseif ( is_page(17) ||  is_child(17) ) : ?>
    
    <div class="subMenuContainer">
    <?php	wp_nav_menu( array( 'items_wrap' => '%3$s', 'container_class' => 'subMenu', 'after' => '<li class="menu-divider">|',  'theme_location' => 'mediacenter' ) ); ?>
    </div><!-- end subMenuContainer -->
    
    <?php endif; ?>

    Any help on this would be most appreciated. I have tried and tried different approaches but nothing is working
    Refer to this site: http://ahminc.com/ahm/services/

Viewing 1 replies (of 1 total)
  • Thread Starter kparker2

    (@kparker2)

    I resolved this by taking out my conditional statement out of the header.php and placing it in a the content-page.php . Which is weird, because I thought you should be able to use if/or conditional even if you are calling a custom function from functions.php?
    Anyway, cheers

Viewing 1 replies (of 1 total)
  • The topic ‘Need Help! Do this if child page of a Page’ is closed to new replies.