WordPress.org

Ready to get started?Download WordPress

Forums

Trouble Showing Child Pages when a Parent is Currently Displayed (4 posts)

  1. Matthew Trust
    Member
    Posted 3 years ago #

    Hello,

    I have spent the past few hours trying to solve a seemingly very simple problem, but to no avail. I have a left sidebar on my page that consists of an unordered list that I'm using for navigational purposes (these are my "pages" in WordPress-speak). I am using the following code to call my left sidebar:

    <div id="sidebar-left">
         <ul>
            <li>
            <a href="<?php bloginfo('url'); ?>">Home</a></li>
    	<?php wp_list_pages('sort_column=menu_order&title_li=&depth=0'); ?>
         </ul>
    </div>

    Currently, this code makes my list to appear as follows:
    Parent Page
    Parent Page
    Child Page
    Child Page
    Child Page
    Parent Page
    Child Page
    Child Page
    Parent Page
    (etc...you get the idea)

    I have lots of child pages within the parents and want to hide these on my main page, except for when my audience clicks on one of the parents. It should look as follows, assuming the second parent has been clicked:

    Parent
    Parent
    Child
    Child
    Child
    Parent
    Parent
    (etc.)

    I've tried changing the "depth" field to "1", but all this does is permanently hide all the child pages (which makes me wonder, why bother to include child or sub-pages at all if they're simply going to disappear if depth is 1). I also tried changing the CSS around, but I must've not done something right because it didn't work. Again, I want the list of child pages to be available only when the parent page is displayed.

    Thanks!!

  2. esmi
    Forum Moderator
    Posted 3 years ago #

    Try googling on "jQuery accordion menu".

  3. Matthew Trust
    Member
    Posted 3 years ago #

    Thanks Esmi, but isn't there a simpler way to do this without downloading any widgets? I installed the jquery accordion menu plug-in but it's not working correctly since my theme "doesn't support menus."

  4. esmi
    Forum Moderator
    Posted 3 years ago #

    It's normally something that is built into a theme. So you'd need to edit your theme to suit.

Topic Closed

This topic has been closed to new replies.

About this Topic