Opened 18 years ago
Closed 17 years ago
#4351 closed enhancement (fixed)
Modify Walker_Page to add current_page_tree class for some style
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 2.5 | Priority: | normal |
Severity: | normal | Version: | 2.3 |
Component: | Template | Keywords: | Walker_Page wp_list_pages developer-feedback |
Focuses: | Cc: |
Description
I thought this might be a useful suggestion since CSS has no "parent" selector.
Basically just a slight mod to class Walker_Page that "should" identify the current page location and depth and add a current_page_tree class to the preceding UL. There may be a better implementation, and I did play with adding class levels to the UL(s), but I thought I would keep this simple as a starting point for this ticket.
Here is a sample CSS that seems to work with the attached patch to produce CSS based collapsable lists
div.sidebar li.page_item ul { display: none; } div.sidebar li.current_page_item ul { display: block; } div.sidebar li.current_page_parent ul { display: block; } div.sidebar li.page_item ul.current_page_tree { display: block; } div.sidebar li.page_item ul.current_page_tree ul { display: block; } }}
Attachments (3)
Change History (10)
#3
@
17 years ago
I actually ran into this again working on a recent site that wanted collapsible sidebar menus. I had to write a small widget with a custom Walker_Page class, walk_page_tree function, and wp_list_pages function... and noticed it was a one-line change.
I remembered this old ticket, so I thought I would add an updated patch especially since the change is the addition of a single line of code to modify the class name output.
#4
@
17 years ago
Driving home in nasty south Louisiana rain while avoiding Mardi Gras revelers cleared my head.
Attached as r-6666-classes.php.txt is the rewrite of the Walker_Page class I'm using in a widget.
This minor rewrite is designed to insert two new classes:
current_page_root - is placed on the root UL.
current_page_branch - is placed on the preceding LI.
I believe current_page_root would probably work for most folks. This also introduces a new class function and two new variables in an attempt to call get_page as little as possible.
There may be easier / better performing methods.
#5
@
17 years ago
Thanks for proposing the patch, it is well thought-out and in pretty good shape.
I have a few observations and suggestions:
Ideally, the _current_page should be assigned in the constructor when Walker_Page class is first created.
However, since we are still sticking to php4 class format, I think assigning it in start_lvl is ok.
$marker_page_parent the default invalid value should be set to something non-zero, such as –1, because top level pages have parent 0;
–1 will always be invalid, thus it is safer in the future.
Beside, shall we use _current_page_parent,
instead of marker_page_parent as it is more consistent?
In light of this, in the initialization:
var $_current_page_parent = -1;
Since this Walker_Page is used in many places, we need to do careful testing and regression, including the page widgets, page listing on sidebar, etc.
Patch for Walker_Page to add UL class current_page_tree