WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Page is ancestor of? (6 posts)

  1. id eric
    Member
    Posted 5 years ago #

    Is there a similar cat_is_ancestor_of function for pages?

    reference:
    http://codex.wordpress.org/Function_Reference/cat_is_ancestor_of

  2. MichaelH
    Member
    Posted 5 years ago #

    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";
    }
    ?>
  3. id eric
    Member
    Posted 5 years ago #

    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?

  4. MichaelH
    Member
    Posted 5 years ago #

    Could look at some examples using wp_list_pages().

  5. id eric
    Member
    Posted 5 years ago #

    Yes, thank you. :)

  6. id eric
    Member
    Posted 5 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic