Accessibility: Add aria-current
to the Archives, Categories, and Recent Posts widgets output.
The `aria-current` attribute is a simple, effective, way to help assistive technology users orientate themselves within a list of items. Continues the introduction in core of the `aria-current` attribute after [41359] and following changes. Props audrasjb, melchoyce. Fixes #47094. git-svn-id: https://develop.svn.wordpress.org/trunk@46163 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
4b3eb36a5b
commit
0dbd752500
@ -206,6 +206,7 @@ class Walker_Category extends Walker {
|
||||
foreach ( $_current_terms as $_current_term ) {
|
||||
if ( $category->term_id == $_current_term->term_id ) {
|
||||
$css_classes[] = 'current-cat';
|
||||
$link = str_replace( '<a', '<a aria-current="page"', $link );
|
||||
} elseif ( $category->term_id == $_current_term->parent ) {
|
||||
$css_classes[] = 'current-cat-parent';
|
||||
}
|
||||
|
@ -1735,18 +1735,19 @@ function get_the_post_type_description() {
|
||||
* @return string HTML link content for archive.
|
||||
*/
|
||||
function get_archives_link( $url, $text, $format = 'html', $before = '', $after = '', $selected = false ) {
|
||||
$text = wptexturize( $text );
|
||||
$url = esc_url( $url );
|
||||
$text = wptexturize( $text );
|
||||
$url = esc_url( $url );
|
||||
$aria_current = $selected ? ' aria-current="page"' : '';
|
||||
|
||||
if ( 'link' == $format ) {
|
||||
if ( 'link' === $format ) {
|
||||
$link_html = "\t<link rel='archives' title='" . esc_attr( $text ) . "' href='$url' />\n";
|
||||
} elseif ( 'option' == $format ) {
|
||||
} elseif ( 'option' === $format ) {
|
||||
$selected_attr = $selected ? " selected='selected'" : '';
|
||||
$link_html = "\t<option value='$url'$selected_attr>$before $text $after</option>\n";
|
||||
} elseif ( 'html' == $format ) {
|
||||
$link_html = "\t<li>$before<a href='$url'>$text</a>$after</li>\n";
|
||||
} elseif ( 'html' === $format ) {
|
||||
$link_html = "\t<li>$before<a href='$url'$aria_current>$text</a>$after</li>\n";
|
||||
} else { // custom
|
||||
$link_html = "\t$before<a href='$url'>$text</a>$after\n";
|
||||
$link_html = "\t$before<a href='$url'$aria_current>$text</a>$after\n";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -93,11 +93,16 @@ class WP_Widget_Recent_Posts extends WP_Widget {
|
||||
<ul>
|
||||
<?php foreach ( $r->posts as $recent_post ) : ?>
|
||||
<?php
|
||||
$post_title = get_the_title( $recent_post->ID );
|
||||
$title = ( ! empty( $post_title ) ) ? $post_title : __( '(no title)' );
|
||||
$post_title = get_the_title( $recent_post->ID );
|
||||
$title = ( ! empty( $post_title ) ) ? $post_title : __( '(no title)' );
|
||||
$aria_current = '';
|
||||
|
||||
if ( get_queried_object_id() === $recent_post->ID ) {
|
||||
$aria_current = ' aria-current="page"';
|
||||
}
|
||||
?>
|
||||
<li>
|
||||
<a href="<?php the_permalink( $recent_post->ID ); ?>"><?php echo $title; ?></a>
|
||||
<a href="<?php the_permalink( $recent_post->ID ); ?>"<?php echo $aria_current; ?>><?php echo $title; ?></a>
|
||||
<?php if ( $show_date ) : ?>
|
||||
<span class="post-date"><?php echo get_the_date( '', $recent_post->ID ); ?></span>
|
||||
<?php endif; ?>
|
||||
|
Loading…
Reference in New Issue
Block a user