]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/class-walker-page.php
WordPress 4.4.1
[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          * @see Walker::$tree_type
20          * @since 2.1.0
21          * @var string
22          */
23         public $tree_type = 'page';
24
25         /**
26          * @see Walker::$db_fields
27          * @since 2.1.0
28          * @todo Decouple this.
29          * @var array
30          */
31         public $db_fields = array ('parent' => 'post_parent', 'id' => 'ID');
32
33         /**
34          * @see Walker::start_lvl()
35          * @since 2.1.0
36          *
37          * @param string $output Passed by reference. Used to append additional content.
38          * @param int    $depth  Depth of page. Used for padding.
39          * @param array  $args
40          */
41         public function start_lvl( &$output, $depth = 0, $args = array() ) {
42                 $indent = str_repeat("\t", $depth);
43                 $output .= "\n$indent<ul class='children'>\n";
44         }
45
46         /**
47          * @see Walker::end_lvl()
48          * @since 2.1.0
49          *
50          * @param string $output Passed by reference. Used to append additional content.
51          * @param int    $depth  Depth of page. Used for padding.
52          * @param array  $args
53          */
54         public function end_lvl( &$output, $depth = 0, $args = array() ) {
55                 $indent = str_repeat("\t", $depth);
56                 $output .= "$indent</ul>\n";
57         }
58
59         /**
60          * @see Walker::start_el()
61          * @since 2.1.0
62          *
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.
67          * @param array  $args
68          */
69         public function start_el( &$output, $page, $depth = 0, $args = array(), $current_page = 0 ) {
70                 if ( $depth ) {
71                         $indent = str_repeat( "\t", $depth );
72                 } else {
73                         $indent = '';
74                 }
75
76                 $css_class = array( 'page_item', 'page-item-' . $page->ID );
77
78                 if ( isset( $args['pages_with_children'][ $page->ID ] ) ) {
79                         $css_class[] = 'page_item_has_children';
80                 }
81
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';
86                         }
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';
91                         }
92                 } elseif ( $page->ID == get_option('page_for_posts') ) {
93                         $css_class[] = 'current_page_parent';
94                 }
95
96                 /**
97                  * Filter the list of CSS classes to include with each page item in the list.
98                  *
99                  * @since 2.8.0
100                  *
101                  * @see wp_list_pages()
102                  *
103                  * @param array   $css_class    An array of CSS classes to be applied
104                  *                             to each list item.
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.
109                  */
110                 $css_classes = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page ) );
111
112                 if ( '' === $page->post_title ) {
113                         /* translators: %d: ID of a post */
114                         $page->post_title = sprintf( __( '#%d (no title)' ), $page->ID );
115                 }
116
117                 $args['link_before'] = empty( $args['link_before'] ) ? '' : $args['link_before'];
118                 $args['link_after'] = empty( $args['link_after'] ) ? '' : $args['link_after'];
119
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>',
123                         $css_classes,
124                         get_permalink( $page->ID ),
125                         $args['link_before'],
126                         apply_filters( 'the_title', $page->post_title, $page->ID ),
127                         $args['link_after']
128                 );
129
130                 if ( ! empty( $args['show_date'] ) ) {
131                         if ( 'modified' == $args['show_date'] ) {
132                                 $time = $page->post_modified;
133                         } else {
134                                 $time = $page->post_date;
135                         }
136
137                         $date_format = empty( $args['date_format'] ) ? '' : $args['date_format'];
138                         $output .= " " . mysql2date( $date_format, $time );
139                 }
140         }
141
142         /**
143          * @see Walker::end_el()
144          * @since 2.1.0
145          *
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.
149          * @param array  $args
150          */
151         public function end_el( &$output, $page, $depth = 0, $args = array() ) {
152                 $output .= "</li>\n";
153         }
154
155 }