Make WordPress Core

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: ev3rywh3re's profile ev3rywh3re Owned by: ev3rywh3re's profile ev3rywh3re
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)

walker-page-tree-diff.txt (713 bytes) - added by ev3rywh3re 18 years ago.
Patch for Walker_Page to add UL class current_page_tree
r-6662-classes.php.txt (668 bytes) - added by ev3rywh3re 17 years ago.
Simple patch for revision 6662
r-6666-classes.php.txt (2.1 KB) - added by ev3rywh3re 17 years ago.
Changes to Walker_Page class to allow additional CSS for page root and branch

Download all attachments as: .zip

Change History (10)

@ev3rywh3re
18 years ago

Patch for Walker_Page to add UL class current_page_tree

#1 @ev3rywh3re
18 years ago

  • Keywords Walker_Page wp_list_pages has-patch added

#2 @Nazgul
18 years ago

  • Milestone changed from 2.3 to 2.4

@ev3rywh3re
17 years ago

Simple patch for revision 6662

#3 @ev3rywh3re
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.

@ev3rywh3re
17 years ago

Changes to Walker_Page class to allow additional CSS for page root and branch

#4 @ev3rywh3re
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 @hailin
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.

#6 @lloydbudd
17 years ago

  • Keywords developer-feedback added; has-patch removed
  • Owner changed from anonymous to ev3rywh3re

#7 @ev3rywh3re
17 years ago

  • Resolution set to fixed
  • Status changed from new to closed

This looks to be fixed by [7074] and is a dupe of #5562. I've tested this even by back porting the new get_post_ancestors() and the [7074] version of Walker_Page seems to do as advertised.

Note: See TracTickets for help on using tickets.