[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Custom page walker for this theme. 4 * 5 * @package WordPress 6 * @subpackage Twenty_Twenty 7 * @since 1.0.0 8 */ 9 10 if ( ! class_exists( 'TwentyTwenty_Walker_Page' ) ) { 11 /** 12 * CUSTOM PAGE WALKER 13 * A custom walker for pages. 14 */ 15 class TwentyTwenty_Walker_Page extends Walker_Page { 16 17 /** 18 * Outputs the beginning of the current element in the tree. 19 * 20 * @see Walker::start_el() 21 * @since 2.1.0 22 * 23 * @param string $output Used to append additional content. Passed by reference. 24 * @param WP_Post $page Page data object. 25 * @param int $depth Optional. Depth of page. Used for padding. Default 0. 26 * @param array $args Optional. Array of arguments. Default empty array. 27 * @param int $current_page Optional. Page ID. Default 0. 28 */ 29 public function start_el( &$output, $page, $depth = 0, $args = array(), $current_page = 0 ) { 30 31 if ( isset( $args['item_spacing'] ) && 'preserve' === $args['item_spacing'] ) { 32 $t = "\t"; 33 $n = "\n"; 34 } else { 35 $t = ''; 36 $n = ''; 37 } 38 if ( $depth ) { 39 $indent = str_repeat( $t, $depth ); 40 } else { 41 $indent = ''; 42 } 43 44 $css_class = array( 'page_item', 'page-item-' . $page->ID ); 45 46 if ( isset( $args['pages_with_children'][ $page->ID ] ) ) { 47 $css_class[] = 'page_item_has_children'; 48 } 49 50 if ( ! empty( $current_page ) ) { 51 $_current_page = get_post( $current_page ); 52 if ( $_current_page && in_array( $page->ID, $_current_page->ancestors, true ) ) { 53 $css_class[] = 'current_page_ancestor'; 54 } 55 if ( $page->ID === $current_page ) { 56 $css_class[] = 'current_page_item'; 57 } elseif ( $_current_page && $page->ID === $_current_page->post_parent ) { 58 $css_class[] = 'current_page_parent'; 59 } 60 } elseif ( get_option( 'page_for_posts' ) === $page->ID ) { 61 $css_class[] = 'current_page_parent'; 62 } 63 64 /** 65 * Filters the list of CSS classes to include with each page item in the list. 66 * 67 * @since 2.8.0 68 * 69 * @see wp_list_pages() 70 * 71 * @param string[] $css_class An array of CSS classes to be applied to each list item. 72 * @param WP_Post $page Page data object. 73 * @param int $depth Depth of page, used for padding. 74 * @param array $args An array of arguments. 75 * @param int $current_page ID of the current page. 76 */ 77 $css_classes = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page ) ); 78 $css_classes = $css_classes ? ' class="' . esc_attr( $css_classes ) . '"' : ''; 79 80 if ( '' === $page->post_title ) { 81 /* translators: %d: ID of a post */ 82 $page->post_title = sprintf( __( '#%d (no title)', 'twentytwenty' ), $page->ID ); 83 } 84 85 $args['link_before'] = empty( $args['link_before'] ) ? '' : $args['link_before']; 86 $args['link_after'] = empty( $args['link_after'] ) ? '' : $args['link_after']; 87 88 $atts = array(); 89 $atts['href'] = get_permalink( $page->ID ); 90 $atts['aria-current'] = ( $page->ID === $current_page ) ? 'page' : ''; 91 92 /** 93 * Filters the HTML attributes applied to a page menu item's anchor element. 94 * 95 * @since 4.8.0 96 * 97 * @param array $atts { 98 * The HTML attributes applied to the menu item's `<a>` element, empty strings are ignored. 99 * 100 * @type string $href The href attribute. 101 * @type string $aria_current The aria-current attribute. 102 * } 103 * @param WP_Post $page Page data object. 104 * @param int $depth Depth of page, used for padding. 105 * @param array $args An array of arguments. 106 * @param int $current_page ID of the current page. 107 */ 108 $atts = apply_filters( 'page_menu_link_attributes', $atts, $page, $depth, $args, $current_page ); 109 110 $attributes = ''; 111 foreach ( $atts as $attr => $value ) { 112 if ( ! empty( $value ) ) { 113 $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); 114 $attributes .= ' ' . $attr . '="' . $value . '"'; 115 } 116 } 117 118 $args['list_item_before'] = ''; 119 $args['list_item_after'] = ''; 120 121 // Wrap the link in a div and append a sub menu toggle. 122 if ( isset( $args['show_toggles'] ) && true === $args['show_toggles'] ) { 123 // Wrap the menu item link contents in a div, used for positioning. 124 $args['list_item_before'] = '<div class="ancestor-wrapper">'; 125 $args['list_item_after'] = ''; 126 127 // Add a toggle to items with children. 128 if ( isset( $args['pages_with_children'][ $page->ID ] ) ) { 129 130 $toggle_target_string = '.menu-modal .page-item-' . $page->ID . ' > ul'; 131 $toggle_duration = twentytwenty_toggle_duration(); 132 133 // Add the sub menu toggle. 134 $args['list_item_after'] .= '<button class="toggle sub-menu-toggle fill-children-current-color" data-toggle-target="' . $toggle_target_string . '" data-toggle-type="slidetoggle" data-toggle-duration="' . absint( $toggle_duration ) . '" aria-expanded="false"><span class="screen-reader-text">' . __( 'Show sub menu', 'twentytwenty' ) . '</span>' . twentytwenty_get_theme_svg( 'chevron-down' ) . '</button>'; 135 136 } 137 138 // Close the wrapper. 139 $args['list_item_after'] .= '</div><!-- .ancestor-wrapper -->'; 140 } 141 142 // Add icons to menu items with children. 143 if ( isset( $args['show_sub_menu_icons'] ) && true === $args['show_sub_menu_icons'] ) { 144 if ( isset( $args['pages_with_children'][ $page->ID ] ) ) { 145 $args['list_item_after'] = '<span class="icon"></span>'; 146 } 147 } 148 149 $output .= $indent . sprintf( 150 '<li%s>%s<a%s>%s%s%s</a>%s', 151 $css_classes, 152 $args['list_item_before'], 153 $attributes, 154 $args['link_before'], 155 /** This filter is documented in wp-includes/post-template.php */ 156 apply_filters( 'the_title', $page->post_title, $page->ID ), 157 $args['link_after'], 158 $args['list_item_after'] 159 ); 160 161 if ( ! empty( $args['show_date'] ) ) { 162 if ( 'modified' === $args['show_date'] ) { 163 $time = $page->post_modified; 164 } else { 165 $time = $page->post_date; 166 } 167 168 $date_format = empty( $args['date_format'] ) ? '' : $args['date_format']; 169 $output .= ' ' . mysql2date( $date_format, $time ); 170 } 171 } 172 } 173 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sat Nov 23 20:47:33 2019 | Cross-referenced by PHPXref 0.7 |