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.

I am trying to create a menu, with sub-pages and sub-sub-pages of a current page.

I want the menu to work as a dropdown, where the sub-sub-pages for a sub-pages are shown when the user clicks the sub-page, and hidden again if the user clicks on the sub-page a second time. So it is important that the sub-pages in the menu are not links.

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

Can anyone help? :)

share|improve this question

1 Answer 1

up vote 0 down vote accepted

You can use get_page_children function to retrieve all sub pages

$the_query = new WP_Query( array( 'post_type' => 'page', 'posts_per_page' => -1 ) );
$children = get_page_children( get_the_ID(), $the_query->query() );

if ( !empty( $children ) ) {
    foreach ( $children as $child ) {
        // render menu
    }
}
share|improve this answer

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.