- Timestamp:
- 11/12/2018 11:19:13 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/5.0/src/wp-content/themes/twentynineteen/inc/template-functions.php
r43842 r43892 72 72 function twentynineteen_get_the_archive_title() { 73 73 if ( is_category() ) { 74 $title = esc_html__( 'Category Archives: ', 'twentynineteen' ) . '<span class="page-description">' . single_term_title( '', false ) . '</span>';74 $title = __( 'Category Archives: ', 'twentynineteen' ) . '<span class="page-description">' . single_term_title( '', false ) . '</span>'; 75 75 } elseif ( is_tag() ) { 76 $title = esc_html__( 'Tag Archives: ', 'twentynineteen' ) . '<span class="page-description">' . single_term_title( '', false ) . '</span>';76 $title = __( 'Tag Archives: ', 'twentynineteen' ) . '<span class="page-description">' . single_term_title( '', false ) . '</span>'; 77 77 } elseif ( is_author() ) { 78 $title = esc_html__( 'Author Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_author_meta( 'display_name' ) . '</span>';78 $title = __( 'Author Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_author_meta( 'display_name' ) . '</span>'; 79 79 } elseif ( is_year() ) { 80 $title = esc_html__( 'Yearly Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_date( _x( 'Y', 'yearly archives date format', 'twentynineteen' ) ) . '</span>';80 $title = __( 'Yearly Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_date( _x( 'Y', 'yearly archives date format', 'twentynineteen' ) ) . '</span>'; 81 81 } elseif ( is_month() ) { 82 $title = esc_html__( 'Monthly Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_date( _x( 'F Y', 'monthly archives date format', 'twentynineteen' ) ) . '</span>';82 $title = __( 'Monthly Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_date( _x( 'F Y', 'monthly archives date format', 'twentynineteen' ) ) . '</span>'; 83 83 } elseif ( is_day() ) { 84 $title = esc_html__( 'Daily Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_date() . '</span>';84 $title = __( 'Daily Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_date() . '</span>'; 85 85 } elseif ( is_post_type_archive() ) { 86 $title = esc_html__( 'Post Type Archives: ', 'twentynineteen' ) . '<span class="page-description">' . post_type_archive_title( '', false ) . '</span>';86 $title = __( 'Post Type Archives: ', 'twentynineteen' ) . '<span class="page-description">' . post_type_archive_title( '', false ) . '</span>'; 87 87 } elseif ( is_tax() ) { 88 88 $tax = get_taxonomy( get_queried_object()->taxonomy ); … … 90 90 $title = sprintf( esc_html__( '%s Archives:', 'twentynineteen' ), $tax->labels->singular_name ); 91 91 } else { 92 $title = esc_html__( 'Archives:', 'twentynineteen' );92 $title = __( 'Archives:', 'twentynineteen' ); 93 93 } 94 94 return $title; … … 112 112 return true; 113 113 } 114 115 /** 116 * Add custom sizes attribute to responsive image functionality for post thumbnails. 117 * 118 * @origin Twenty Nineteen 1.0 119 * 120 * @param array $attr Attributes for the image markup. 121 * @return string Value for use in post thumbnail 'sizes' attribute. 122 */ 123 function twentynineteen_post_thumbnail_sizes_attr( $attr ) { 124 125 if ( is_admin() ) { 126 return $attr; 127 } 128 129 if ( ! is_singular() ) { 130 $attr['sizes'] = '(max-width: 34.9rem) calc(100vw - 2rem), (max-width: 53rem) calc(8 * (100vw / 12)), (min-width: 53rem) calc(6 * (100vw / 12)), 100vw'; 131 } 132 133 return $attr; 134 } 135 add_filter( 'wp_get_attachment_image_attributes', 'twentynineteen_post_thumbnail_sizes_attr', 10, 1 ); 114 136 115 137 /** … … 141 163 function twentynineteen_get_discussion_data() { 142 164 static $discussion, $post_id; 165 143 166 $current_post_id = get_the_ID(); 144 if ( $current_post_id === $post_id ) { /* If we have discussion information for post ID, return cached object */145 return $discussion; 146 } 147 $authors = array();148 $commenters = array();149 $user_id = -1; // is_user_logged_in() ? get_current_user_id() : -1; 150 $comments 167 if ( $current_post_id === $post_id ) { 168 return $discussion; /* If we have discussion information for post ID, return cached object */ 169 } else { 170 $post_id = $current_post_id; 171 } 172 173 $comments = get_comments( 151 174 array( 152 175 'post_id' => $current_post_id, … … 154 177 'order' => get_option( 'comment_order', 'asc' ), /* Respect comment order from Settings » Discussion. */ 155 178 'status' => 'approve', 179 'number' => 20, /* Only retrieve the last 20 comments, as the end goal is just 6 unique authors */ 156 180 ) 157 181 ); 182 183 $authors = array(); 158 184 foreach ( $comments as $comment ) { 159 $comment_user_id = (int) $comment->user_id; 160 if ( $comment_user_id !== $user_id ) { 161 $authors[] = ( $comment_user_id > 0 ) ? $comment_user_id : $comment->comment_author_email; 162 $commenters[] = $comment->comment_author_email; 163 } 164 } 185 $authors[] = ( (int) $comment->user_id > 0 ) ? (int) $comment->user_id : $comment->comment_author_email; 186 } 187 165 188 $authors = array_unique( $authors ); 166 $responses = count( $commenters );167 $commenters = array_unique( $commenters );168 $post_id = $current_post_id;169 189 $discussion = (object) array( 170 'authors' => array_slice( $authors, 0, 6 ), /* Unique authors commenting on post (a subset of), excluding current user. */ 171 'commenters' => count( $commenters ), /* Number of commenters involved in discussion, excluding current user. */ 172 'responses' => $responses, /* Number of responses, excluding responses from current user. */ 190 'authors' => array_slice( $authors, 0, 6 ), /* Six unique authors commenting on the post. */ 191 'responses' => get_comments_number( $current_post_id ), /* Number of responses. */ 173 192 ); 193 174 194 return $discussion; 175 195 } 196 197 /** 198 * Add an extra menu to our nav for our priority+ navigation to use 199 * 200 * @param object $nav_menu Nav menu. 201 * @param object $args Nav menu args. 202 * @return string More link for hidden menu items. 203 */ 204 function twentynineteen_add_ellipses_to_nav( $nav_menu, $args ) { 205 206 if ( 'menu-1' === $args->theme_location ) : 207 208 $nav_menu .= '<div class="main-menu-more" >'; 209 $nav_menu .= '<ul class="main-menu" tabindex="0">'; 210 $nav_menu .= '<li class="menu-item menu-item-has-children">'; 211 $nav_menu .= '<a href="#" class="screen-reader-text" aria-label="More" aria-haspopup="true" aria-expanded="false">' . esc_html( 'More', 'twentynineteen' ) . '</a>'; 212 $nav_menu .= '<span class="submenu-expand main-menu-more-toggle" tabindex="-1">'; 213 $nav_menu .= twentynineteen_get_icon_svg( 'arrow_drop_down_ellipsis' ); 214 $nav_menu .= '</span>'; 215 $nav_menu .= '<ul class="sub-menu hidden-links is-hidden">'; 216 $nav_menu .= '<li id="menu-item--1" class="mobile-parent-nav-menu-item menu-item--1">'; 217 $nav_menu .= '<a class="menu-item-link-return" id="menu-item-link-return-1877" href="#menu-item-link-1877" onclick="event.preventDefault();" tabindex="-1">'; 218 $nav_menu .= twentynineteen_get_icon_svg( 'chevron_left' ); 219 $nav_menu .= esc_html__( 'Back', 'twentynineteen' ); 220 $nav_menu .= '</a>'; 221 $nav_menu .= '</li>'; 222 $nav_menu .= '</ul>'; 223 $nav_menu .= '</li>'; 224 $nav_menu .= '</ul>'; 225 $nav_menu .= '</div>'; 226 227 endif; 228 229 return $nav_menu; 230 } 231 add_filter( 'wp_nav_menu', 'twentynineteen_add_ellipses_to_nav', 10, 2 ); 176 232 177 233 /** … … 217 273 // @todo Only do this for nested submenus? If on a first-level submenu, then really the link could be "#" since the desire is to remove the target entirely. 218 274 $link = sprintf( 219 '<a class="menu-item-link-return" id="%1$s" href="%2$s" onclick="%3$s" tabindex="-1">%4$s', 220 esc_attr( "menu-item-link-return-{$item->original_id}" ), 221 esc_attr( "#menu-item-link-{$item->original_id}" ), 222 esc_attr( 'event.preventDefault();' ), 275 '<span class="menu-item-link-return" tabindex="-1">%s', 223 276 twentynineteen_get_icon_svg( 'chevron_left', 24 ) 224 277 ); 225 278 279 // replace opening <a> with <span> 226 280 $output = preg_replace( 227 281 '/<a\s.*?>/', … … 230 284 1 // Limit. 231 285 ); 286 287 // replace closing </a> with </span> 288 $output = preg_replace( 289 '#</a>#i', 290 '</span>', 291 $output, 292 1 // Limit. 293 ); 294 232 295 } elseif ( in_array( 'menu-item-has-children', $item->classes, true ) ) { 233 // Add an ID to the link element itself to facilitate navigation from submenu back to parent.234 $output = preg_replace( '/(?<=<a\s)/', sprintf( ' id="%s" ', esc_attr( "menu-item-link-{$item->ID}" ) ), $output );235 296 236 297 // Add SVG icon to parent items. 237 if ( 0 === $depth ) { 238 $icon = twentynineteen_get_icon_svg( 'keyboard_arrow_down', 24 ); 239 } else { 240 $icon = twentynineteen_get_icon_svg( 'chevron_right', 24 ); 241 } 242 243 // @todo We might as well just go back to using the SVG element if the link approach is not suitable for no-JS environments. 244 $link = sprintf( 245 '<a class="mobile-submenu-expand" href="%s" onclick="%s" tabindex="-1">%s</a>', 246 esc_attr( "#menu-item-link-return-{$item->ID}" ), 247 esc_attr( 'event.preventDefault();' ), 298 $icon = twentynineteen_get_icon_svg( 'keyboard_arrow_down', 24 ); 299 300 $output .= sprintf( 301 '<span class="submenu-expand" tabindex="-1">%s</span>', 248 302 $icon 249 303 ); 250 251 $output .= $link;252 $output .= "<span class='desktop-submenu-expand'>$icon</span>";253 304 } 254 305
Note: See TracChangeset
for help on using the changeset viewer.