Support » Fixing WordPress » get_post_ancestors with wp_query

  • Hi.

    I’m building a site using WordPress as a CMS and which uses pages almost exclusively to organise content.

    I’m trying to find a way of creating a navigation menu which lists all the child and grandchild pages of top level pages, so the menu stays the same as you browse child and grandchild pages. There’s a couple of solutions around which work perfectly when using wp_list_pages and get_post_ancestors but I would like to include text excerpts from the pages too, and for that I think I need to use a wp_query.

    I wonder if someone can help?

    The wp_list_pages version of the code is as follows:

    global $wp_query;
    $post = $wp_query->post;
    $ancestors = get_post_ancestors($post);
    if( empty($post->post_parent) ) {
        $parent = $post->ID;
    } else {
        $parent = end($ancestors);
    if(wp_list_pages("title_li=&child_of=$parent&echo=0&sort_column=menu_order" )) { ?>
    <h3><?php $page = get_post($parent);
    echo $page->post_title; ?></h3>
    <ul id="secondary-nav">
        <?php wp_list_pages("title_li=&child_of=$parent" ); ?>
    </ul><!-- #secondary-nav -->
    <?php } ?>

    (code adapted from this post)

    Essentially I’m trying (and failing) to replace the second wp_list_pages bit with code which enables me to include text excerpts as well as just page titles and permalinks.

    Any help much appreciated!

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘get_post_ancestors with wp_query’ is closed to new replies.