3 * Post API: Walker_Page class
11 * Core walker class used to create an HTML list of pages.
17 class Walker_Page extends Walker {
19 * @see Walker::$tree_type
23 public $tree_type = 'page';
26 * @see Walker::$db_fields
28 * @todo Decouple this.
31 public $db_fields = array ('parent' => 'post_parent', 'id' => 'ID');
34 * @see Walker::start_lvl()
37 * @param string $output Passed by reference. Used to append additional content.
38 * @param int $depth Depth of page. Used for padding.
41 public function start_lvl( &$output, $depth = 0, $args = array() ) {
42 $indent = str_repeat("\t", $depth);
43 $output .= "\n$indent<ul class='children'>\n";
47 * @see Walker::end_lvl()
50 * @param string $output Passed by reference. Used to append additional content.
51 * @param int $depth Depth of page. Used for padding.
54 public function end_lvl( &$output, $depth = 0, $args = array() ) {
55 $indent = str_repeat("\t", $depth);
56 $output .= "$indent</ul>\n";
60 * @see Walker::start_el()
63 * @param string $output Passed by reference. Used to append additional content.
64 * @param object $page Page data object.
65 * @param int $depth Depth of page. Used for padding.
66 * @param int $current_page Page ID.
69 public function start_el( &$output, $page, $depth = 0, $args = array(), $current_page = 0 ) {
71 $indent = str_repeat( "\t", $depth );
76 $css_class = array( 'page_item', 'page-item-' . $page->ID );
78 if ( isset( $args['pages_with_children'][ $page->ID ] ) ) {
79 $css_class[] = 'page_item_has_children';
82 if ( ! empty( $current_page ) ) {
83 $_current_page = get_post( $current_page );
84 if ( $_current_page && in_array( $page->ID, $_current_page->ancestors ) ) {
85 $css_class[] = 'current_page_ancestor';
87 if ( $page->ID == $current_page ) {
88 $css_class[] = 'current_page_item';
89 } elseif ( $_current_page && $page->ID == $_current_page->post_parent ) {
90 $css_class[] = 'current_page_parent';
92 } elseif ( $page->ID == get_option('page_for_posts') ) {
93 $css_class[] = 'current_page_parent';
97 * Filter the list of CSS classes to include with each page item in the list.
101 * @see wp_list_pages()
103 * @param array $css_class An array of CSS classes to be applied
105 * @param WP_Post $page Page data object.
106 * @param int $depth Depth of page, used for padding.
107 * @param array $args An array of arguments.
108 * @param int $current_page ID of the current page.
110 $css_classes = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page ) );
112 if ( '' === $page->post_title ) {
113 /* translators: %d: ID of a post */
114 $page->post_title = sprintf( __( '#%d (no title)' ), $page->ID );
117 $args['link_before'] = empty( $args['link_before'] ) ? '' : $args['link_before'];
118 $args['link_after'] = empty( $args['link_after'] ) ? '' : $args['link_after'];
120 /** This filter is documented in wp-includes/post-template.php */
121 $output .= $indent . sprintf(
122 '<li class="%s"><a href="%s">%s%s%s</a>',
124 get_permalink( $page->ID ),
125 $args['link_before'],
126 apply_filters( 'the_title', $page->post_title, $page->ID ),
130 if ( ! empty( $args['show_date'] ) ) {
131 if ( 'modified' == $args['show_date'] ) {
132 $time = $page->post_modified;
134 $time = $page->post_date;
137 $date_format = empty( $args['date_format'] ) ? '' : $args['date_format'];
138 $output .= " " . mysql2date( $date_format, $time );
143 * @see Walker::end_el()
146 * @param string $output Passed by reference. Used to append additional content.
147 * @param object $page Page data object. Not used.
148 * @param int $depth Depth of page. Not Used.
151 public function end_el( &$output, $page, $depth = 0, $args = array() ) {
152 $output .= "</li>\n";