This plugin uses DOM to add a class (current_page_ancestor) to the li tag of each page that is an ancestor of the current one. With a little CSS, you can have nice collapsing menus. This code assumes that your pages are listed using the usual wp_list_pages function, and that they are in an element with the id of nav.
#nav ul li.current_page_item ul,
#nav ul li.current_page_ancestor ul {
display:block;
}
#nav ul li.current_page_item ul ul {
display:none;
}
I wanted collapsing menus in WordPress, not Javascript based, but something that would display only top level pages AND pages that are either children of the current page or children of the ancestors of the current page. It may sound confusing, but it’s really quite logical. Take a look:
Given a page structure like this:
Web Programming > WordPress > > Themes > > > CSS > > > JavaScript > > > PHP > > Plugins > > Functions > CubeCart > Gallery Templates > Free Designs Portfolio > Sites About Contact
On the main page, I’d like to display all the top level pages: Web Programming, Templates, Portfolio, About, Contact
On page ‘Web Programming’ I would like to display:
Web Programming > WordPress > CubeCart > Gallery Templates Portfolio About Contact
On page ‘WordPress’ I would like to display:
Web Programming > WordPress > > Themes > > Plugins > > Functions > CubeCart > Gallery Templates Portfolio About Contact
On page ‘Themes’ I would like to display:
Web Programming > WordPress > > Themes > > > CSS > > > JavaScript > > > PHP > > Plugins > > Functions > CubeCart > Gallery Templates Portfolio About Contact
The problem was that to display the pages like that, I really needed to know all ancestors of the current page. Now that this plugin classes those, I can do exactly what I wanted.

Looks like your server is interpreting the .php file literally, thus I’m just getting blank pages when trying to download. Maybe it needs to be presented as .src or .txt?
Thank you for pointing that out. I changed the attachment to a .phps file. If you want to save it, just right click and save. Otherwise, the link will display the contents as color coded PHP source code.
Chalk it up to blatant self interest — I want to use the plugin! *grin*
Additionally, maybe I’m losing my marbles a bit here, but isn’t a closing PHP short tag missing from the end of the file?
Actually, it’s optional, and after doing a fair bit of work with Zend Framework, I’ve come to appreciate their coding standards.
Could you explain how to use it?
Sorry but i can’t find how to apply the “current_page_ancestor” class to my content…
Regards
Adrien
Ooops sorry, it was because of the “missing the closing tag (”?>”)”
Hey I’m getting the following error when attempting to activate the plugin:
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in PATH/wp-mark-parent-pages.php on line 35
Oh, also, whoops! I’m using version 2.3.3 of wordpress.
All PHP snippets, plugins, etc that you find on this site require PHP5.2 as per the Go PHP 5 directive.
Ahh yeah that would explain it, thanks for the quick reply!
Good plugin