125 if ( $page->ID == $current_page ) { |
128 if ( $page->ID == $current_page ) { |
126 $css_class[] = 'current_page_item'; |
129 $css_class[] = 'current_page_item'; |
127 } elseif ( $_current_page && $page->ID == $_current_page->post_parent ) { |
130 } elseif ( $_current_page && $page->ID == $_current_page->post_parent ) { |
128 $css_class[] = 'current_page_parent'; |
131 $css_class[] = 'current_page_parent'; |
129 } |
132 } |
130 } elseif ( $page->ID == get_option('page_for_posts') ) { |
133 } elseif ( $page->ID == get_option( 'page_for_posts' ) ) { |
131 $css_class[] = 'current_page_parent'; |
134 $css_class[] = 'current_page_parent'; |
132 } |
135 } |
133 |
136 |
134 /** |
137 /** |
135 * Filters the list of CSS classes to include with each page item in the list. |
138 * Filters the list of CSS classes to include with each page item in the list. |
136 * |
139 * |
137 * @since 2.8.0 |
140 * @since 2.8.0 |
138 * |
141 * |
139 * @see wp_list_pages() |
142 * @see wp_list_pages() |
140 * |
143 * |
141 * @param array $css_class An array of CSS classes to be applied |
144 * @param string[] $css_class An array of CSS classes to be applied to each list item. |
142 * to each list item. |
145 * @param WP_Post $page Page data object. |
143 * @param WP_Post $page Page data object. |
146 * @param int $depth Depth of page, used for padding. |
144 * @param int $depth Depth of page, used for padding. |
147 * @param array $args An array of arguments. |
145 * @param array $args An array of arguments. |
148 * @param int $current_page ID of the current page. |
146 * @param int $current_page ID of the current page. |
|
147 */ |
149 */ |
148 $css_classes = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page ) ); |
150 $css_classes = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page ) ); |
|
151 $css_classes = $css_classes ? ' class="' . esc_attr( $css_classes ) . '"' : ''; |
149 |
152 |
150 if ( '' === $page->post_title ) { |
153 if ( '' === $page->post_title ) { |
151 /* translators: %d: ID of a post */ |
154 /* translators: %d: ID of a post */ |
152 $page->post_title = sprintf( __( '#%d (no title)' ), $page->ID ); |
155 $page->post_title = sprintf( __( '#%d (no title)' ), $page->ID ); |
153 } |
156 } |
154 |
157 |
155 $args['link_before'] = empty( $args['link_before'] ) ? '' : $args['link_before']; |
158 $args['link_before'] = empty( $args['link_before'] ) ? '' : $args['link_before']; |
156 $args['link_after'] = empty( $args['link_after'] ) ? '' : $args['link_after']; |
159 $args['link_after'] = empty( $args['link_after'] ) ? '' : $args['link_after']; |
157 |
160 |
158 $atts = array(); |
161 $atts = array(); |
159 $atts['href'] = get_permalink( $page->ID ); |
162 $atts['href'] = get_permalink( $page->ID ); |
|
163 $atts['aria-current'] = ( $page->ID == $current_page ) ? 'page' : ''; |
160 |
164 |
161 /** |
165 /** |
162 * Filters the HTML attributes applied to a page menu item's anchor element. |
166 * Filters the HTML attributes applied to a page menu item's anchor element. |
163 * |
167 * |
164 * @since 4.8.0 |
168 * @since 4.8.0 |
165 * |
169 * |
166 * @param array $atts { |
170 * @param array $atts { |
167 * The HTML attributes applied to the menu item's `<a>` element, empty strings are ignored. |
171 * The HTML attributes applied to the menu item's `<a>` element, empty strings are ignored. |
168 * |
172 * |
169 * @type string $href The href attribute. |
173 * @type string $href The href attribute. |
|
174 * @type string $aria_current The aria-current attribute. |
170 * } |
175 * } |
171 * @param WP_Post $page Page data object. |
176 * @param WP_Post $page Page data object. |
172 * @param int $depth Depth of page, used for padding. |
177 * @param int $depth Depth of page, used for padding. |
173 * @param array $args An array of arguments. |
178 * @param array $args An array of arguments. |
174 * @param int $current_page ID of the current page. |
179 * @param int $current_page ID of the current page. |
176 $atts = apply_filters( 'page_menu_link_attributes', $atts, $page, $depth, $args, $current_page ); |
181 $atts = apply_filters( 'page_menu_link_attributes', $atts, $page, $depth, $args, $current_page ); |
177 |
182 |
178 $attributes = ''; |
183 $attributes = ''; |
179 foreach ( $atts as $attr => $value ) { |
184 foreach ( $atts as $attr => $value ) { |
180 if ( ! empty( $value ) ) { |
185 if ( ! empty( $value ) ) { |
181 $value = esc_attr( $value ); |
186 $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); |
182 $attributes .= ' ' . $attr . '="' . $value . '"'; |
187 $attributes .= ' ' . $attr . '="' . $value . '"'; |
183 } |
188 } |
184 } |
189 } |
185 |
190 |
186 $output .= $indent . sprintf( |
191 $output .= $indent . sprintf( |
187 '<li class="%s"><a%s>%s%s%s</a>', |
192 '<li%s><a%s>%s%s%s</a>', |
188 $css_classes, |
193 $css_classes, |
189 $attributes, |
194 $attributes, |
190 $args['link_before'], |
195 $args['link_before'], |
191 /** This filter is documented in wp-includes/post-template.php */ |
196 /** This filter is documented in wp-includes/post-template.php */ |
192 apply_filters( 'the_title', $page->post_title, $page->ID ), |
197 apply_filters( 'the_title', $page->post_title, $page->ID ), |