Viewing 5 replies - 1 through 5 (of 5 total)
  • Assuming your page object is in $post (like inside a normal post loop):

    <?php
    if (in_array("95", $post->ancestors)) {
        echo "page id 95 is an ancestor of this page";
    }
    ?>
    Thread Starter id eric

    (@insidedesign)

    I am looking to display a sub-navigation in the sidebar of all the child pages for a parent page. Is this the best way to achieve this?

    Could look at some examples using wp_list_pages().

    Thread Starter id eric

    (@insidedesign)

    Yes, thank you. ??

    Thread Starter id eric

    (@insidedesign)

    Here is my end result for those that come across this thread:

    // [not shown] special cases for post categories up here (using is_ancestor_of function)
    
    // now for the pages
    elseif(is_page()) {
    	//get post id
    	global $post;
    	$page = $post->ID;
    
    		// Some Menu for a set of pages
    		if($page == "68" || $post->post_parent == "68" ) { ?>
    			<h3>Some Title For this Set of Pages</h3>
    			<ul>
    				<?php wp_list_pages('orderby=name&child_of=68&title_li='); ?>
    			</ul>
    		<?php }
    
    		// Another Menu for another set of pages
    		if ($page == '751' || $post->post_parent == "751" ) { ?>
    			<h3>Some Other Title For this Set of Pages</h3>
    			<ul>
    				<?php wp_list_pages('depth=2&child_of=751&title_li='); ?>
    			</ul>
    		<?php }
    } else { ?>
    // standard sidebar stuff for untargeted pages or posts
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Page is ancestor of?’ is closed to new replies.