This is pretty easy, as WordPress sets css classes for the parent pages.
Default we hide all sublists (ul) from the menu with
.menu ul {
display: none;
}
Then when the parent page is selected we use the css classes that are set by WordPress to show the sublists again.
.menu .current_page_ancestor, .menu .current_page_parent {
display: block;
}
So all you need is this in your template
Template:
<ul class="menu">
<?php wp_list_pages('title_li=') ?>
</ul>
and this in your css file.
CSS:
.menu ul {
display: none;
}
.menu .current_page_ancestor > ul, .menu .current_page_parent > ul {
display: block;
}
Related Posts:
- Add infinite scroll to content splitted post
- How to give paged links custom title?
- Two Search pages, One search form
- Blank Pages with # URL & Google
- Combining ‘depth’ with ‘include’ in wp_list_pages()
- Removing Parent Page URL While Keeping the Navigation Intact
- How to change the order of the Front Page so it doesn’t appear first
- Listing all child-pages of a parent-page on the parent-page and each child-page?
- Ordering Pages and Increasing Navigation
- Displaying Current Page Number Conditionally
- Static Website No Titles But Still Nav
- Make Audio Element Persistent Across Pages
- wordpress page navigation numeric pagination showing same posts on each navigation
- How to make page navigation just below the content?
- displaying child pages in columns when on a parent page
- Advanced Multi Tier Navigation across columns
- WP-navi plugin and post sorted alphabetically
- Get the content of a specific page (by ID)
- featured image as background image on pages
- Show Default Editor on Blog Page ( Administration Panel )
- Create pages automatically if they don’t exist
- Can I display submenus in groups, using wp_list_pages?
- Can I display the widget admin in the page admin?
- Internal Links to Pages in PHP?
- Restrict acceess of a page in backend
- Assign title-specific class to list items in menu based on WP pages
- Modify theme to get page excerpts on front page
- get_page_by_title not working when used with a variable
- How to make certain page templates visible to admin only
- Editing Pages that Have Already Been Published
- The entire content of my WordPress page has disappeared
- What is the proper way to get contents of a page?
- Getting child content
- Clean URL link for page without number
- Can I include Javascript/jQuery in a page?
- Adminbar Missing “Edit Page”
- conditional tags- how to use with shortcodes
- Guest authors, sort of like Wikipedia, but more theme-able
- Show own shortcode data on each page
- Pages views limit [closed]
- Having wordpress page accesss issue under sub-directory
- How to make my category archive behave like a page
- Add external css to Contact Page
- how to edit source code of specific page in wordpress?
- Where can i make an html change to a specific page [closed]
- Cannot enter “::before” for li tag when editing a WordPress page
- This code won’t find authors page?
- WordPress backend:How to hide some specific pages under Pages–>All Pages
- Different header for each page in child theme of twenty thirteen
- Change a Page’s Header Image
- Dynamic href link to Contact Page
- Restrict the list of parent pages to only those which are created by current user
- Use content from one page in another template
- Is there a way to schedule changes to a page?
- Is it possible to change slugs’ default behaviour?
- List child pages within page template
- Option for pages order in backend
- Return subpages of an author if the parent page was published by an other author
- append one page content into another
- Allow a user to edit their own page and profile only
- on page creation few inline style properties gets removed
- way to make all pages with certain tags public?
- Page not appearing under its Parent
- Separate URL for a specific page
- Next and Previous Page links based on ‘Order’ attribute
- register_rest_field only for specific page
- Update Pages ONLY from Stage to Live (not products)
- Change page width in refined magazine/mag and news theme
- How do you run code on a specific page without missing the init hook?
- Every change made by “Author” role is going to “pending review”
- if is_page() is not working with wp_redirect
- Display meta data attribute in user profile
- WordPress default theme cannot get full page on entry content div
- Assign Parent Page – Now 404 Error
- Create multiple custom HTML pages
- WordPress displays widgets out of whack
- Add homepage to the list of pages in the Footer Widget
- How to remove the duplicate title tags and duplicate meta descriptions?
- Customise the_title in admin area
- Add pagination to search.php page
- How to turn post into pages and via versa?
- How do I get my page “About” to show up on my WordPress site?
- Featured Image not displaying in a page
- Pulling posts tagged with similar title name
- Filter posts by author selected in page
- Temporary download page or restrict static download page based on how the user got to the page?
- List Parent page with sub pages
- simple category search form returns full text – but I need excerpts
- Naming custom page templates
- How can I use Page editor for two separate templates?
- Sort the data in WordPress using get-page-by-title
- Order pages by date
- wordpress user profile page
- In WP, Google map error initMap is not a function [closed]
- how can i get the page_ID in nav li [closed]
- Split Page Links
- Ask for template when adding a new page
- How to view front-end of WordPress website, using Atom?
- Can’t create new pages in wordpress
- Custom template is not showing up in templates dropdown list after re-naming it