StudioPress Community Forums
  StudioPress Community Forums > Forums > General Discussion
For help and support, access to your downloads, or to manage your account please log into My StudioPress.

These forums have been set to read-only so you can browse the existing topics for any questions you may have.

For general discussion on WordPress, CSS and design (NOT for support) visit the new Community Forums.
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 08-28-2012, 01:15 PM
KHCreative KHCreative is offline
Registered User
Pro Plus Member
 
Join Date: Jul 2012
Posts: 43
Default List pages only if subpages exist

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 ) != ) { 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
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Parent Pages Linking to subpages wparlaman General Discussion 4 07-31-2009 06:11 PM
top navigation - links for pages & subpages M.Schif General Discussion 1 07-17-2009 10:40 AM


All times are GMT -5. The time now is 02:44 PM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.