Hey guys,
I'm trying to build a navigation menu for sub-pages, that only shows up when you're on the parent page. I also need the parent page to show up in the menu as well. I thought I had it, but the code below is also showing the parent page link on pages that have no sub pages. Anyone care to show me the mistake I'm making?
PHP Code:
/*-----------------------------------------
Check if a page has any children / subpages
-----------------------------------------*/
function has_children($post_id) {
$children = get_pages("child_of=$post_id");
if( count( $children ) != 0 ) { return true; } // Has Children
else { return false; } // No children
}
add_action ('genesis_before_post_title', 'subpage_nav');
function subpage_nav(){
if ( has_children($page->ID) ) {
echo '<div id="pagenav">' . '<ul class="clearfix">';
wp_list_pages( array('title_li'=>'','include'=>get_post_top_ancestor_id()) );
wp_list_pages( array('title_li'=>'','depth'=>1,'child_of'=>get_post_top_ancestor_id()) );
echo '</ul>' . '</div>';
}
else{
}
}
Thank you for your time,
Keith