• Hey guys,

    I have a site where I have some pages who have subpages. I need to list those subpages and the parent page. I want to do this conditionally so that the parent page doesn’t get list on a page without children.

    Here is my code:

    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($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;
    
    	};

    This is listing the parent and child page. What am I doing wrong.

    Thank you,
    Keith

Viewing 1 replies (of 1 total)
  • This is listing the parent and child page.

    nothing wrong, this is how it is programmed in these two lines:

    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()) );

    top line is for showing the parent, bottom line is for showing the children.

Viewing 1 replies (of 1 total)
  • The topic ‘Check page for child pages’ is closed to new replies.