[wp-hackers] Page ancestry and CSS

SoJ Web sojweb at indiana.edu
Sun Jul 26 20:31:15 UTC 2009

Question about wp_list_pages() and page ancestry:

I have a site that displays a page menu on each page, but there are  
hundreds of pages, so they can't all be displayed in the menu. My  
design requires that top-level pages always be displayed, and that  
children of a page be hidden, unless that page is current, or a parent  
of a current page. I filter out children of non-current pages  
altogether in the wp_list_pages() call, and I'm using CSS to hide  
children of sibling pages, and grandchildren of the current page. This  
works fine if the hierarchy is only 2-deep; beyond that, however, it  
fails, because WordPress only adds the "current-page-parent" class to  
a page's immediate parents, and not to the parents of the parent.

My solution to this was to make a modification to the start_el()  
function of the Walker_Page class (line 1168 in v2.8.2) that adds the  
"current_page_parent" class to all parents of a page, and not just its  
immediate parent. That makes it trivial to do with CSS. It's 9 lines  
of code, and I wanted to do it with a plugin, but didn't see where I  
could hook in.

My question is: Does anyone have any better ideas? Obviously, I'd  
rather not be modifying core files. I'm hoping I'm just missing  
something really simple. Thanks.


On Jul 25, 2009, at 20:12 PM, scribu wrote:

> I've started working on a patch here:
> http://core.trac.wordpress.org/ticket/10487
> -- 
> http://scribu.net
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers

More information about the wp-hackers mailing list