]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/class-walker-page.php
WordPress 4.5.1-scripts
[autoinstalls/wordpress.git] / wp-includes / class-walker-page.php
1 <?php
2 /**
3  * Post API: Walker_Page class
4  *
5  * @package WordPress
6  * @subpackage Template
7  * @since 4.4.0
8  */
9
10 /**
11  * Core walker class used to create an HTML list of pages.
12  *
13  * @since 2.1.0
14  *
15  * @see Walker
16  */
17 class Walker_Page extends Walker {
18
19         /**
20          * What the class handles.
21          *
22          * @since 2.1.0
23          * @access public
24          * @var string
25          *
26          * @see Walker::$tree_type
27          */
28         public $tree_type = 'page';
29
30         /**
31          * Database fields to use.
32          *
33          * @since 2.1.0
34          * @access private
35          * @var array
36          *
37          * @see Walker::$db_fields
38          * @todo Decouple this.
39          */
40         public $db_fields = array( 'parent' => 'post_parent', 'id' => 'ID' );
41
42         /**
43          * Outputs the beginning of the current level in the tree before elements are output.
44          *
45          * @since 2.1.0
46          * @access public
47          *
48          * @see Walker::start_lvl()
49          *
50          * @param string $output Passed by reference. Used to append additional content.
51          * @param int    $depth  Optional. Depth of page. Used for padding. Default 0.
52          * @param array  $args   Optional. Arguments for outputing the next level.
53          *                       Default empty array.
54          */
55         public function start_lvl( &$output, $depth = 0, $args = array() ) {
56                 $indent = str_repeat("\t", $depth);
57                 $output .= "\n$indent<ul class='children'>\n";
58         }
59
60         /**
61          * Outputs the end of the current level in the tree after elements are output.
62          *
63          * @since 2.1.0
64          * @access public
65          *
66          * @see Walker::end_lvl()
67          *
68          * @param string $output Passed by reference. Used to append additional content.
69          * @param int    $depth  Optional. Depth of page. Used for padding. Default 0.
70          * @param array  $args   Optional. Arguments for outputting the end of the current level.
71          *                       Default empty array.
72          */
73         public function end_lvl( &$output, $depth = 0, $args = array() ) {
74                 $indent = str_repeat("\t", $depth);
75                 $output .= "$indent</ul>\n";
76         }
77
78         /**
79          * Outputs the beginning of the current element in the tree.
80          *
81          * @see Walker::start_el()
82          * @since 2.1.0
83          * @access public
84          *
85          * @param string  $output       Used to append additional content. Passed by reference.
86          * @param WP_Post $page         Page data object.
87          * @param int     $depth        Optional. Depth of page. Used for padding. Default 0.
88          * @param array   $args         Optional. Array of arguments. Default empty array.
89          * @param int     $current_page Optional. Page ID. Default 0.
90          */
91         public function start_el( &$output, $page, $depth = 0, $args = array(), $current_page = 0 ) {
92                 if ( $depth ) {
93                         $indent = str_repeat( "\t", $depth );
94                 } else {
95                         $indent = '';
96                 }
97
98                 $css_class = array( 'page_item', 'page-item-' . $page->ID );
99
100                 if ( isset( $args['pages_with_children'][ $page->ID ] ) ) {
101                         $css_class[] = 'page_item_has_children';
102                 }
103
104                 if ( ! empty( $current_page ) ) {
105                         $_current_page = get_post( $current_page );
106                         if ( $_current_page && in_array( $page->ID, $_current_page->ancestors ) ) {
107                                 $css_class[] = 'current_page_ancestor';
108                         }
109                         if ( $page->ID == $current_page ) {
110                                 $css_class[] = 'current_page_item';
111                         } elseif ( $_current_page && $page->ID == $_current_page->post_parent ) {
112                                 $css_class[] = 'current_page_parent';
113                         }
114                 } elseif ( $page->ID == get_option('page_for_posts') ) {
115                         $css_class[] = 'current_page_parent';
116                 }
117
118                 /**
119                  * Filter the list of CSS classes to include with each page item in the list.
120                  *
121                  * @since 2.8.0
122                  *
123                  * @see wp_list_pages()
124                  *
125                  * @param array   $css_class    An array of CSS classes to be applied
126                  *                              to each list item.
127                  * @param WP_Post $page         Page data object.
128                  * @param int     $depth        Depth of page, used for padding.
129                  * @param array   $args         An array of arguments.
130                  * @param int     $current_page ID of the current page.
131                  */
132                 $css_classes = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page ) );
133
134                 if ( '' === $page->post_title ) {
135                         /* translators: %d: ID of a post */
136                         $page->post_title = sprintf( __( '#%d (no title)' ), $page->ID );
137                 }
138
139                 $args['link_before'] = empty( $args['link_before'] ) ? '' : $args['link_before'];
140                 $args['link_after'] = empty( $args['link_after'] ) ? '' : $args['link_after'];
141
142                 $output .= $indent . sprintf(
143                         '<li class="%s"><a href="%s">%s%s%s</a>',
144                         $css_classes,
145                         get_permalink( $page->ID ),
146                         $args['link_before'],
147                         /** This filter is documented in wp-includes/post-template.php */
148                         apply_filters( 'the_title', $page->post_title, $page->ID ),
149                         $args['link_after']
150                 );
151
152                 if ( ! empty( $args['show_date'] ) ) {
153                         if ( 'modified' == $args['show_date'] ) {
154                                 $time = $page->post_modified;
155                         } else {
156                                 $time = $page->post_date;
157                         }
158
159                         $date_format = empty( $args['date_format'] ) ? '' : $args['date_format'];
160                         $output .= " " . mysql2date( $date_format, $time );
161                 }
162         }
163
164         /**
165          * Outputs the end of the current element in the tree.
166          *
167          * @since 2.1.0
168          * @access public
169          *
170          * @see Walker::end_el()
171          *
172          * @param string  $output Used to append additional content. Passed by reference.
173          * @param WP_Post $page   Page data object. Not used.
174          * @param int     $depth  Optional. Depth of page. Default 0 (unused).
175          * @param array   $args   Optional. Array of arguments. Default empty array.
176          */
177         public function end_el( &$output, $page, $depth = 0, $args = array() ) {
178                 $output .= "</li>\n";
179         }
180
181 }