WordPress.org

Ready to get started?Download WordPress

Forums

Only Display Sub Pages when Top Level Page is Clicked (11 posts)

  1. rosemckay
    Member
    Posted 5 years ago #

    Hello,
    I'm searching through the documentation and I'm not sure what I need to look for to get my page display to only show the top level pages, unless a top level page is clicked on, then I want it to show the sub pages that go under just that one top level page that was clicked. Can some one point me in the right direction?

    Thanks!

  2. MichaelH
    Member
    Posted 5 years ago #

  3. rosemckay
    Member
    Posted 5 years ago #

    Thanks for the info, I'm looking through the links you gave but I don't seem to be able to find anything that will hide the sub pages until their parent page is clicked. Perhaps I need to know something more specific like the name of the argument that would accomplish this?

    Thanks!

  4. MichaelH
    Member
    Posted 5 years ago #

    Use the depth=1 argument with wp_list_pages() to display all 'top-level' pages.

  5. esmi
    Forum Moderator
    Posted 5 years ago #

    Try this:

    <?php
    $my_pages = wp_list_pages('title_li=&depth=1&echo=0');
    if (is_page()) {
    	$this_page = $post->ID;
    	if ($post->post_parent) $this_page= $post->post_parent;
    	$children = get_page_children($this_page, get_pages());
    	if($children) {
    		$my_pages .= "<li>\n".'<ul class="subpages">';
    		foreach($children as $child) {
    			$my_pages .= wp_list_pages('title_li=&include='.$child->ID.'&echo=0');
    		}
    		$my_pages .= '</ul></li>';
    	}
    }
    echo $my_pages;
    ?>
  6. rosemckay
    Member
    Posted 5 years ago #

    Thanks esmi, that works, kinda. It shows sub pages when I click on a parent page, however it shows them under the rest of the links instead of under the parent page. Is this easy to fix?

  7. rosemckay
    Member
    Posted 5 years ago #

    Just to illustrate it your code makes it looks like this:

    Parent #1
    Parent #2
    Parent #3
    Parent #4
    - Child #1a
    - Child #1b

    I think that will confuse site visitors (it confuses me!). Is there a way to make it look like this?

    Parent #1
    - Child #1a
    - Child #1b
    Parent #2
    Parent #3
    Parent #4

  8. esmi
    Forum Moderator
    Posted 5 years ago #

    it shows them under the rest of the links instead of under the parent page. Is this easy to fix?

    Could be that my approach isn't suitable for you. I sometimes show the subpage links within the parent page in a small "Related Pages" box. I have used the approach in horizontal menu with child pages appearing in on a 2nd line under the main nav but not in a vertical menu as yet.

    Sounds like you need something like the Fold Pages plugin/widget. However, be warned that it may not work under WP2.8, so please proceed with caution.

  9. Christian Schenk
    Member
    Posted 5 years ago #

    I've hacked a plugin that displays a hierarchical menu. It was used on several pages and works just nice under WP2.8.

  10. rosemckay
    Member
    Posted 5 years ago #

    hi! that was my thoughts with your code, esmi. it would be an elegant solution for showing child pages in a different area/box. I like the idea and would love to design a layout to accommodate such an arrangement.

    I wanted to come back and say that I found a plug in called SuperSlider-Menu. It's doing exactly what I need and it slides which is a nice touch.

    Thanks for all the help, hopefully this thread will be helpful to someone else too.

  11. wlindley
    Member
    Posted 4 years ago #

    you might also try the hierarchical-pages widget

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.