mirror of
https://github.com/WordPress/WordPress.git
synced 2024-09-17 18:11:11 +02:00
7fbb094586
With a focus on business sites, it will let you get down to business in style. Initial development occurred on GitHub. See: https://github.com/WordPress/twentyseventeen Props melchoyce, laurelfulford, davidakennedy, grapplerulrich, manishsongirkar36, joefusco, smyoon315, b-07, rabmalin, mrahmadawais, hardeepasrani, implenton, acmethemes, claudiosanches, valeriutihai, pressionate, sgr33n, doughamlin, zodiac1978, tsl143, nikschavan, joshcummingsdesign, enodekciw, jordesign, patilvikasj, ryelle, mahesh901122, williampatton, juanfra, imnok, littlebigthing, mor10, samikeijonen, celloexpressions, akshayvinchurkar, davidmosterd, hiddenpearls, netweb, pratikchaskar, taggon, nukaga, ranh, yoavf, karmatosed, sandesh055, adammacias, noplanman, yogasukma, binarymoon, swapnilld, swissspidy, joyously, allancole, rianrietveld, sixhours, alex27, themeshaper, mapk, leobaiano. See #38372. Built from https://develop.svn.wordpress.org/trunk@38833 git-svn-id: http://core.svn.wordpress.org/trunk@38776 1a063a9b-81f0-0310-95a4-ce76da25c4cd
163 lines
5.2 KiB
PHP
163 lines
5.2 KiB
PHP
<?php
|
|
/**
|
|
* Custom template tags for this theme
|
|
*
|
|
* Eventually, some of the functionality here could be replaced by core features.
|
|
*
|
|
* @package WordPress
|
|
* @subpackage Twenty_Seventeen
|
|
* @since 1.0
|
|
*/
|
|
|
|
if ( ! function_exists( 'twentyseventeen_posted_on' ) ) :
|
|
/**
|
|
* Prints HTML with meta information for the current post-date/time and author.
|
|
*/
|
|
function twentyseventeen_posted_on() {
|
|
|
|
// Get the author name; wrap it in a link.
|
|
$byline = sprintf(
|
|
_x( 'by %s', 'post author', 'twentyseventeen' ),
|
|
'<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . get_the_author() . '</a></span>'
|
|
);
|
|
|
|
// Finally, let's write all of this to the page.
|
|
echo '<span class="posted-on">' . twentyseventeen_time_link() . '</span><span class="byline"> ' . $byline . '</span>'; // WPCS: XSS OK.
|
|
}
|
|
endif;
|
|
|
|
|
|
if ( ! function_exists( 'twentyseventeen_time_link' ) ) :
|
|
/**
|
|
* Gets a nicely formatted string for the published date.
|
|
*/
|
|
function twentyseventeen_time_link() {
|
|
$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
|
|
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
|
|
$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
|
|
}
|
|
|
|
$time_string = sprintf( $time_string,
|
|
get_the_date( DATE_W3C ),
|
|
get_the_date(),
|
|
get_the_modified_date( DATE_W3C ),
|
|
get_the_modified_date()
|
|
);
|
|
|
|
// Wrap the time string in a link, and preface it with 'Posted on'.
|
|
return '<span class="screen-reader-text">' . _x( 'Posted on', 'post date', 'twentyseventeen' ) . '</span> <a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>';
|
|
}
|
|
endif;
|
|
|
|
|
|
if ( ! function_exists( 'twentyseventeen_entry_footer' ) ) :
|
|
/**
|
|
* Prints HTML with meta information for the categories, tags and comments.
|
|
*/
|
|
function twentyseventeen_entry_footer() {
|
|
|
|
/* translators: used between list items, there is a space after the comma */
|
|
$separate_meta = __( ', ', 'twentyseventeen' );
|
|
|
|
// Get Categories for posts.
|
|
$categories_list = get_the_category_list( $separate_meta );
|
|
|
|
// Get Tags for posts.
|
|
$tags_list = get_the_tag_list( '', $separate_meta );
|
|
|
|
// We don't want to output .entry-footer if it will be empty, so make sure its not.
|
|
if ( ( ( twentyseventeen_categorized_blog() && $categories_list ) || $tags_list ) || get_edit_post_link() ) {
|
|
|
|
echo '<footer class="entry-footer">';
|
|
|
|
if ( 'post' === get_post_type() ) {
|
|
if ( ( $categories_list && twentyseventeen_categorized_blog() ) || $tags_list ) {
|
|
echo '<span class="cat-tags-links">';
|
|
|
|
// Make sure there's more than one category before displaying.
|
|
if ( $categories_list && twentyseventeen_categorized_blog() ) {
|
|
echo '<span class="cat-links">' . twentyseventeen_get_svg( array( 'icon' => 'folder-open' ) ) . '<span class="screen-reader-text">' . __( 'Categories', 'twentyseventeen' ) . '</span>' . $categories_list . '</span>'; // WPCS: XSS OK.
|
|
}
|
|
|
|
if ( $tags_list ) {
|
|
echo '<span class="tags-links">' . twentyseventeen_get_svg( array( 'icon' => 'hashtag' ) ) . '<span class="screen-reader-text">' . __( 'Tags', 'twentyseventeen' ) . '</span>' . $tags_list . '</span>'; // WPCS: XSS OK.
|
|
}
|
|
|
|
echo '</span>';
|
|
}
|
|
}
|
|
|
|
twentyseventeen_edit_link();
|
|
|
|
echo '</footer> <!-- .entry-footer -->';
|
|
}
|
|
}
|
|
endif;
|
|
|
|
|
|
if ( ! function_exists( 'twentyseventeen_edit_link' ) ) :
|
|
/**
|
|
* Returns an accessibility-friendly link to edit a post or page.
|
|
*
|
|
* This also gives us a little context about what exactly we're editing
|
|
* (post or page?) so that users understand a bit more where they are in terms
|
|
* of the template hierarchy and their content. Helpful when/if the single-page
|
|
* layout with multiple posts/pages shown gets confusing.
|
|
*/
|
|
function twentyseventeen_edit_link() {
|
|
|
|
$link = edit_post_link(
|
|
sprintf(
|
|
/* translators: %s: Name of current post */
|
|
__( 'Edit<span class="screen-reader-text"> "%s"</span>', 'twentyseventeen' ),
|
|
get_the_title()
|
|
),
|
|
'<span class="edit-link">',
|
|
'</span>'
|
|
);
|
|
|
|
return $link;
|
|
}
|
|
endif;
|
|
|
|
|
|
/**
|
|
* Returns true if a blog has more than 1 category.
|
|
*
|
|
* @return bool
|
|
*/
|
|
function twentyseventeen_categorized_blog() {
|
|
$category_count = get_transient( 'twentyseventeen_categories' );
|
|
|
|
if ( false === $category_count ) {
|
|
// Create an array of all the categories that are attached to posts.
|
|
$categories = get_categories( array(
|
|
'fields' => 'ids',
|
|
'hide_empty' => 1,
|
|
// We only need to know if there is more than one category.
|
|
'number' => 2,
|
|
) );
|
|
|
|
// Count the number of categories that are attached to the posts.
|
|
$category_count = count( $categories );
|
|
|
|
set_transient( 'twentyseventeen_categories', $category_count );
|
|
}
|
|
|
|
return $category_count > 1;
|
|
}
|
|
|
|
|
|
/**
|
|
* Flush out the transients used in twentyseventeen_categorized_blog.
|
|
*/
|
|
function twentyseventeen_category_transient_flusher() {
|
|
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
|
return;
|
|
}
|
|
// Like, beat it. Dig?
|
|
delete_transient( 'twentyseventeen_categories' );
|
|
}
|
|
add_action( 'edit_category', 'twentyseventeen_category_transient_flusher' );
|
|
add_action( 'save_post', 'twentyseventeen_category_transient_flusher' );
|