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
  #4  
Old 08-28-2012, 05:25 PM
KHCreative KHCreative is offline
Registered User
Pro Plus Member
 
Join Date: Jul 2012
Posts: 43
Default Solved

OK, after much trial and error, I figured it out. I'll post my code here so that someone less may be able to benefit from it some day.

PHP Code:
/*-----------------------------------------
Check if a page has any children / subpages
-----------------------------------------*/
 
function has_children(){
 global 
$post;
 
 if( (
$post->post_parent == && wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0'))
 ||
 (
$post->post_parent && wp_list_pages('title_li=&child_of='.$post->post_parent.'&echo=0'))
 ){
 return 
true;
 } else {
 return 
false;
 }
}
   
 if(!
function_exists('get_post_top_ancestor_id')){
/**
 * Gets the id of the topmost ancestor of the current page. Returns the current
 * page's id if there is no parent.
 * 
 * @uses object $post
 * @return int 
 */
function get_post_top_ancestor_id(){
    global 
$post;
    
    if(
$post->post_parent){
        
$ancestors array_reverse(get_post_ancestors($page->ID));
        return 
$ancestors[0];
    }
    
    return 
$post->ID;
}}


add_action ('genesis_before_post_title''subpage_nav');
    function 
subpage_nav(){
    
        if ( 
is_page() && has_children($post->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{
           }

    } 
 

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 09:53 PM.

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