Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

So I don't really know why I am having so much trouble with this, it seems like functionality in wordpress that should be a bit easier to working with.

Anyhow I need to generate a menu system for a sidebar that looks like this (for a top level page):

<ul>
    <li><a>Sub-Page</a></li>
    <li><a>Sub-Page</a>
        <ul>
            <li><a>Sub-Sub-Page</a></li>
            <li><a>Sub-Sub-Page</a></li>
        </ul>
    </li>
    <li><a>Sub-Page</a>
        <ul>
            <li><a>Sub-Sub-Page</a></li>
            <li><a>Sub-Sub-Page</a></li>
            <li><a>Sub-Sub-Page</a></li>
        </ul>
    </li>
    <li><a>Sub-Page</a></li>
</ul>

On top if this, I need to show the same menu, no matter how deep in the sub pages the user is at.

For example, if I was on a sub-sub-page, then I still wish to show the same menu.

In other words, even if I was at a 3rd level page, it would still show 3rd and 2nd level pages - exactly the same as the above menu.


Thanks for the help in this one!

share|improve this question
    
What is the code that creates the menu? –  s_ha_dum Jan 11 '13 at 1:36
    
I don't really have code that 'creates' the menu besides what I have answered with :P –  Ben Potter Jan 14 '13 at 1:12
add comment

1 Answer 1

up vote 0 down vote accepted

So it turns out to be a bit easier than I thought:

                <?php

                if ($post->post_parent) {
                    $ancestors=get_post_ancestors($post->ID);
                    $root=count($ancestors)-1;
                    $parent = $ancestors[$root];
                } else {
                    $parent = $post->ID;
                }

                ?>

                <?php $args = array(
                    'depth'        => 0,
                    'date_format'  => get_option('date_format'),
                    'child_of'     => $parent,
                    'title_li'     => __(''),
                    'sort_column'  => 'menu_order, post_title'
                ); ?>


                <ul>

                  <?php wp_list_pages( $args ); ?> 

                </ul>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.