Codex tools: Log in
Contents |
The walker class encapsulates the basic functionality necessary to output HTML representing WordPress objects with a tree structure. For instance pages and categories are the two types of objects that the WordPress 2.2 code uses the walker class to enumerate. While one could always display categories as you wished by using right func and looping through them using it takes a great deal of work to arrange subcategories below their parents with proper formatting. The walker class takes care of most of this work for you.
Note that the properties of the Walker class are intended to be set by the extending class and probably should not vary over the lifetime of an instance.
Also the method definitions of start_el, end_el, start_lvl, end_lvl only list one argument but are called using call_user_func_array and it is these arguments that are listed.
class Walker_Page extends Walker {
var $tree_type = 'page';
var $db_fields = array ('parent' =>
'post_parent', 'id' => 'ID');
Thus the Walker_Page class (part of wordpress 2.2) expects that if page is a page object then page->post_parent will give the id of that page's parent and page->ID will give the id of that page.
walk steps through the array $elements one by one. Each time an element is the child of the prior element walk calls start_lvl. Every time an element is processed walk calls start_el and then end_el. Each time an element is no longer below one of the current parents walk calls end_lvl.
See Function_Reference/Walker_Page, Function_Reference/Walker_PageDropDown, Function_Reference/Walker_Category, Function_Reference/Walker_CategoryDropdown, Function_Reference/Walker_Nav_Menu, Function_Reference/Walker_Comment