Ticket #38545: 38545.2.diff
File 38545.2.diff, 5.5 KB (added by , 6 years ago) |
---|
-
src/wp-includes/general-template.php
1472 1472 * Display the archive title based on the queried object. 1473 1473 * 1474 1474 * @since 4.1.0 1475 * @since 5.2.0 Added `$span_class` parameter. 1475 1476 * 1476 1477 * @see get_the_archive_title() 1477 1478 * 1478 * @param string $before Optional. Content to prepend to the title. Default empty. 1479 * @param string $after Optional. Content to append to the title. Default empty. 1479 * @param string $before Optional. Content to prepend to the title. Default empty. 1480 * @param string $after Optional. Content to append to the title. Default empty. 1481 * @param string $span_class Optional. Class name to apply to a span around the archive type description. Default empty 1482 * (no span displayed). 1480 1483 */ 1481 function the_archive_title( $before = '', $after = '' ) {1482 $title = get_the_archive_title( );1484 function the_archive_title( $before = '', $after = '', $span_class = '' ) { 1485 $title = get_the_archive_title( $span_class ); 1483 1486 1484 1487 if ( ! empty( $title ) ) { 1485 1488 echo $before . $title . $after; … … 1490 1493 * Retrieve the archive title based on the queried object. 1491 1494 * 1492 1495 * @since 4.1.0 1496 * @since 5.2.0 Added `$span_class` parameter. 1493 1497 * 1498 * @param string $span_class Optional. Class name to apply to a span around the archive type description. Default empty 1499 * (no span displayed). 1494 1500 * @return string Archive title. 1495 1501 */ 1496 function get_the_archive_title( ) {1502 function get_the_archive_title( $span_class = '' ) { 1497 1503 if ( is_category() ) { 1498 /* translators: Category archive title. %s: Category name */ 1499 $title = sprintf( __( 'Category: %s' ), single_cat_title( '', false ) ); 1504 /* translators: Category archive title. */ 1505 $type = __( 'Category:' ); 1506 $name = single_cat_title( '', false ); 1500 1507 } elseif ( is_tag() ) { 1501 /* translators: Tag archive title. %s: Tag name */ 1502 $title = sprintf( __( 'Tag: %s' ), single_tag_title( '', false ) ); 1508 /* translators: Tag archive title. */ 1509 $type = __( 'Tag:' ); 1510 $name = single_tag_title( '', false ); 1503 1511 } elseif ( is_author() ) { 1504 /* translators: Author archive title. %s: Author name */ 1505 $title = sprintf( __( 'Author: %s' ), '<span class="vcard">' . get_the_author() . '</span>' ); 1512 /* translators: Author archive title. */ 1513 $type = __( 'Author:' ); 1514 /* translators: %s: Author name. */ 1515 $name = sprintf( '<span class="vcard">%s</span>', get_the_author() ); 1506 1516 } elseif ( is_year() ) { 1507 /* translators: Yearly archive title. %s: Year */ 1508 $title = sprintf( __( 'Year: %s' ), get_the_date( _x( 'Y', 'yearly archives date format' ) ) ); 1517 /* translators: Yearly archive title. */ 1518 $type = __( 'Year:' ); 1519 $name = get_the_date( _x( 'Y', 'yearly archives date format' ) ); 1509 1520 } elseif ( is_month() ) { 1510 /* translators: Monthly archive title. %s: Month name and year */ 1511 $title = sprintf( __( 'Month: %s' ), get_the_date( _x( 'F Y', 'monthly archives date format' ) ) ); 1521 /* translators: Monthly archive title. */ 1522 $type = __( 'Month:' ); 1523 $name = get_the_date( _x( 'F Y', 'monthly archives date format' ) ); 1512 1524 } elseif ( is_day() ) { 1513 /* translators: Daily archive title. %s: Date */ 1514 $title = sprintf( __( 'Day: %s' ), get_the_date( _x( 'F j, Y', 'daily archives date format' ) ) ); 1515 } elseif ( is_tax( 'post_format' ) ) { 1525 /* translators: Daily archive title. */ 1526 $type = __( 'Day:' ); 1527 $name = get_the_date( _x( 'F j, Y', 'daily archives date format' ) ); 1528 } elseif ( is_post_type_archive() ) { 1529 /* translators: Post type archive title. */ 1530 $type = __( 'Archives:' ); 1531 $name = post_type_archive_title( '', false ); 1532 } elseif ( is_tax() ) { 1533 $tax = get_taxonomy( get_queried_object()->taxonomy ); 1534 /* translators: Taxonomy singular name */ 1535 $type = sprintf( __( '%s:' ), $tax->labels->singular_name ); 1536 $name = single_term_title( '', false ); 1537 } 1538 1539 if ( is_tax( 'post_format' ) ) { 1516 1540 if ( is_tax( 'post_format', 'post-format-aside' ) ) { 1517 1541 $title = _x( 'Asides', 'post format archive title' ); 1518 1542 } elseif ( is_tax( 'post_format', 'post-format-gallery' ) ) { … … 1532 1556 } elseif ( is_tax( 'post_format', 'post-format-chat' ) ) { 1533 1557 $title = _x( 'Chats', 'post format archive title' ); 1534 1558 } 1535 } elseif ( is_post_type_archive() ) { 1536 /* translators: Post type archive title. %s: Post type name */ 1537 $title = sprintf( __( 'Archives: %s' ), post_type_archive_title( '', false ) ); 1538 } elseif ( is_tax() ) { 1539 $tax = get_taxonomy( get_queried_object()->taxonomy ); 1540 /* translators: Taxonomy term archive title. 1: Taxonomy singular name, 2: Current taxonomy term */ 1541 $title = sprintf( __( '%1$s: %2$s' ), $tax->labels->singular_name, single_term_title( '', false ) ); 1559 } elseif ( isset( $type ) && isset( $name ) ) { 1560 if ( ! empty( $span_class ) ) { 1561 $title = sprintf( '<span class="%s">%s </span>%s', $span_class, $type, $name ); 1562 } else { 1563 $title = sprintf( '%s %s', $type, $name ); 1564 } 1542 1565 } else { 1543 1566 $title = __( 'Archives' ); 1544 1567 } … … 1547 1570 * Filters the archive title. 1548 1571 * 1549 1572 * @since 4.1.0 1573 * @since 5.2.0 Added `$span_class` parameter. 1550 1574 * 1551 1575 * @param string $title Archive title to be displayed. 1576 * @param string $span_class Optional. Class name to apply to the span around the archive type description. Default empty. 1552 1577 */ 1553 return apply_filters( 'get_the_archive_title', $title );1578 return apply_filters( 'get_the_archive_title', $title, $span_class ); 1554 1579 } 1555 1580 1556 1581 /**