2013-07-29 00:55:10 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2013-10-12 00:02:11 +02:00
|
|
|
* Custom template tags for Twenty Fourteen
|
2013-07-29 00:55:10 +02:00
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Twenty_Fourteen
|
2013-10-12 00:02:11 +02:00
|
|
|
* @since Twenty Fourteen 1.0
|
2013-07-29 00:55:10 +02:00
|
|
|
*/
|
|
|
|
|
2013-08-15 05:13:44 +02:00
|
|
|
if ( ! function_exists( 'twentyfourteen_paging_nav' ) ) :
|
2013-07-29 00:55:10 +02:00
|
|
|
/**
|
2013-10-12 00:02:11 +02:00
|
|
|
* Display navigation to next/previous set of posts when applicable.
|
|
|
|
*
|
|
|
|
* @since Twenty Fourteen 1.0
|
2013-07-29 00:55:10 +02:00
|
|
|
*
|
2013-08-15 05:13:44 +02:00
|
|
|
* @return void
|
2013-07-29 00:55:10 +02:00
|
|
|
*/
|
2013-08-15 05:13:44 +02:00
|
|
|
function twentyfourteen_paging_nav() {
|
|
|
|
// Don't print empty markup if there's only one page.
|
2013-11-19 00:11:10 +01:00
|
|
|
if ( $GLOBALS['wp_query']->max_num_pages < 2 ) {
|
2013-08-15 05:13:44 +02:00
|
|
|
return;
|
2013-11-19 00:11:10 +01:00
|
|
|
}
|
2013-07-29 00:55:10 +02:00
|
|
|
|
2013-08-15 05:13:44 +02:00
|
|
|
$paged = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1;
|
|
|
|
$pagenum_link = html_entity_decode( get_pagenum_link() );
|
|
|
|
$query_args = array();
|
|
|
|
$url_parts = explode( '?', $pagenum_link );
|
2013-07-29 00:55:10 +02:00
|
|
|
|
2013-11-19 00:11:10 +01:00
|
|
|
if ( isset( $url_parts[1] ) ) {
|
2013-08-15 05:13:44 +02:00
|
|
|
wp_parse_str( $url_parts[1], $query_args );
|
2013-11-19 00:11:10 +01:00
|
|
|
}
|
2013-07-29 00:55:10 +02:00
|
|
|
|
2013-08-15 05:13:44 +02:00
|
|
|
$pagenum_link = remove_query_arg( array_keys( $query_args ), $pagenum_link );
|
|
|
|
$pagenum_link = trailingslashit( $pagenum_link ) . '%_%';
|
2013-07-29 00:55:10 +02:00
|
|
|
|
2013-08-15 05:13:44 +02:00
|
|
|
$format = $GLOBALS['wp_rewrite']->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : '';
|
|
|
|
$format .= $GLOBALS['wp_rewrite']->using_permalinks() ? user_trailingslashit( 'page/%#%', 'paged' ) : '?paged=%#%';
|
2013-07-29 00:55:10 +02:00
|
|
|
|
2013-12-03 18:06:11 +01:00
|
|
|
// Set up paginated links.
|
|
|
|
$links = paginate_links( array(
|
2013-08-15 05:13:44 +02:00
|
|
|
'base' => $pagenum_link,
|
|
|
|
'format' => $format,
|
|
|
|
'total' => $GLOBALS['wp_query']->max_num_pages,
|
|
|
|
'current' => $paged,
|
|
|
|
'mid_size' => 1,
|
|
|
|
'add_args' => array_map( 'urlencode', $query_args ),
|
|
|
|
'prev_text' => __( '← Previous', 'twentyfourteen' ),
|
|
|
|
'next_text' => __( 'Next →', 'twentyfourteen' ),
|
|
|
|
) );
|
2013-07-29 00:55:10 +02:00
|
|
|
|
2013-08-15 05:13:44 +02:00
|
|
|
if ( $links ) :
|
2013-07-29 00:55:10 +02:00
|
|
|
|
2013-08-15 05:13:44 +02:00
|
|
|
?>
|
|
|
|
<nav class="navigation paging-navigation" role="navigation">
|
|
|
|
<h1 class="screen-reader-text"><?php _e( 'Posts navigation', 'twentyfourteen' ); ?></h1>
|
|
|
|
<div class="pagination loop-pagination">
|
|
|
|
<?php echo $links; ?>
|
|
|
|
</div><!-- .pagination -->
|
|
|
|
</nav><!-- .navigation -->
|
|
|
|
<?php
|
|
|
|
endif;
|
|
|
|
}
|
|
|
|
endif;
|
2013-07-29 00:55:10 +02:00
|
|
|
|
2013-08-15 05:13:44 +02:00
|
|
|
if ( ! function_exists( 'twentyfourteen_post_nav' ) ) :
|
|
|
|
/**
|
2013-10-12 00:02:11 +02:00
|
|
|
* Display navigation to next/previous post when applicable.
|
|
|
|
*
|
|
|
|
* @since Twenty Fourteen 1.0
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2013-08-15 05:13:44 +02:00
|
|
|
function twentyfourteen_post_nav() {
|
|
|
|
// Don't print empty markup if there's nowhere to navigate.
|
|
|
|
$previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
|
|
|
|
$next = get_adjacent_post( false, '', false );
|
|
|
|
|
2013-11-19 00:11:10 +01:00
|
|
|
if ( ! $next && ! $previous ) {
|
2013-08-15 05:13:44 +02:00
|
|
|
return;
|
2013-11-19 00:11:10 +01:00
|
|
|
}
|
2013-07-29 00:55:10 +02:00
|
|
|
|
2013-08-15 05:13:44 +02:00
|
|
|
?>
|
|
|
|
<nav class="navigation post-navigation" role="navigation">
|
|
|
|
<h1 class="screen-reader-text"><?php _e( 'Post navigation', 'twentyfourteen' ); ?></h1>
|
|
|
|
<div class="nav-links">
|
|
|
|
<?php
|
2013-10-25 00:57:34 +02:00
|
|
|
if ( is_attachment() ) :
|
|
|
|
previous_post_link( '%link', __( '<span class="meta-nav">Published In</span>%title', 'twentyfourteen' ) );
|
|
|
|
else :
|
2013-08-15 05:13:44 +02:00
|
|
|
previous_post_link( '%link', __( '<span class="meta-nav">Previous Post</span>%title', 'twentyfourteen' ) );
|
|
|
|
next_post_link( '%link', __( '<span class="meta-nav">Next Post</span>%title', 'twentyfourteen' ) );
|
2013-10-25 00:57:34 +02:00
|
|
|
endif;
|
2013-08-15 05:13:44 +02:00
|
|
|
?>
|
|
|
|
</div><!-- .nav-links -->
|
|
|
|
</nav><!-- .navigation -->
|
2013-07-29 00:55:10 +02:00
|
|
|
<?php
|
|
|
|
}
|
2013-08-15 05:13:44 +02:00
|
|
|
endif;
|
2013-07-29 00:55:10 +02:00
|
|
|
|
|
|
|
if ( ! function_exists( 'twentyfourteen_posted_on' ) ) :
|
|
|
|
/**
|
2013-10-12 00:02:11 +02:00
|
|
|
* Print HTML with meta information for the current post-date/time and author.
|
|
|
|
*
|
|
|
|
* @since Twenty Fourteen 1.0
|
2013-07-29 00:55:10 +02:00
|
|
|
*
|
2013-08-15 05:13:44 +02:00
|
|
|
* @return void
|
2013-07-29 00:55:10 +02:00
|
|
|
*/
|
|
|
|
function twentyfourteen_posted_on() {
|
2013-11-19 00:11:10 +01:00
|
|
|
if ( is_sticky() && is_home() && ! is_paged() ) {
|
2013-07-29 00:55:10 +02:00
|
|
|
echo '<span class="featured-post">' . __( 'Sticky', 'twentyfourteen' ) . '</span>';
|
2013-11-19 00:11:10 +01:00
|
|
|
}
|
2013-07-29 00:55:10 +02:00
|
|
|
|
2013-12-03 18:06:11 +01:00
|
|
|
// Set up and print post meta information.
|
2013-10-09 21:07:09 +02:00
|
|
|
printf( __( '<span class="entry-date"><a href="%1$s" rel="bookmark"><time class="entry-date" datetime="%2$s">%3$s</time></a></span> <span class="byline"><span class="author vcard"><a class="url fn n" href="%4$s" rel="author">%5$s</a></span></span>', 'twentyfourteen' ),
|
2013-07-29 00:55:10 +02:00
|
|
|
esc_url( get_permalink() ),
|
|
|
|
esc_attr( get_the_date( 'c' ) ),
|
|
|
|
esc_html( get_the_date() ),
|
|
|
|
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
|
|
|
|
get_the_author()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
|
|
|
/**
|
2013-10-12 00:02:11 +02:00
|
|
|
* Find out if blog has more than one category.
|
|
|
|
*
|
|
|
|
* @since Twenty Fourteen 1.0
|
2013-07-29 00:55:10 +02:00
|
|
|
*
|
2013-10-12 00:02:11 +02:00
|
|
|
* @return boolean true if blog has more than 1 category
|
2013-07-29 00:55:10 +02:00
|
|
|
*/
|
|
|
|
function twentyfourteen_categorized_blog() {
|
2013-12-03 19:24:10 +01:00
|
|
|
if ( false === ( $all_the_cool_cats = get_transient( 'twentyfourteen_category_count' ) ) ) {
|
2013-07-29 00:55:10 +02:00
|
|
|
// Create an array of all the categories that are attached to posts
|
|
|
|
$all_the_cool_cats = get_categories( array(
|
|
|
|
'hide_empty' => 1,
|
|
|
|
) );
|
|
|
|
|
|
|
|
// Count the number of categories that are attached to the posts
|
|
|
|
$all_the_cool_cats = count( $all_the_cool_cats );
|
|
|
|
|
2013-12-03 19:24:10 +01:00
|
|
|
set_transient( 'twentyfourteen_category_count', $all_the_cool_cats );
|
2013-07-29 00:55:10 +02:00
|
|
|
}
|
|
|
|
|
2013-12-03 19:24:10 +01:00
|
|
|
if ( 1 !== (int) $all_the_cool_cats ) {
|
2013-07-29 00:55:10 +02:00
|
|
|
// This blog has more than 1 category so twentyfourteen_categorized_blog should return true
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
// This blog has only 1 category so twentyfourteen_categorized_blog should return false
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-12-03 18:06:11 +01:00
|
|
|
* Flush out the transients used in twentyfourteen_categorized_blog.
|
2013-07-29 00:55:10 +02:00
|
|
|
*
|
2013-10-12 00:02:11 +02:00
|
|
|
* @since Twenty Fourteen 1.0
|
|
|
|
*
|
|
|
|
* @return void
|
2013-07-29 00:55:10 +02:00
|
|
|
*/
|
|
|
|
function twentyfourteen_category_transient_flusher() {
|
|
|
|
// Like, beat it. Dig?
|
2013-12-03 19:24:10 +01:00
|
|
|
delete_transient( 'twentyfourteen_category_count' );
|
2013-07-29 00:55:10 +02:00
|
|
|
}
|
|
|
|
add_action( 'edit_category', 'twentyfourteen_category_transient_flusher' );
|
2013-08-15 05:13:29 +02:00
|
|
|
add_action( 'save_post', 'twentyfourteen_category_transient_flusher' );
|
2013-10-08 23:22:10 +02:00
|
|
|
|
|
|
|
/**
|
2013-12-04 04:29:10 +01:00
|
|
|
* Display an optional post thumbnail.
|
2013-12-03 18:06:11 +01:00
|
|
|
*
|
2013-12-04 04:29:10 +01:00
|
|
|
* Wraps the post thumbnail in an anchor element on index
|
|
|
|
* views, or a div element when on single views.
|
2013-10-08 23:22:10 +02:00
|
|
|
*
|
2013-11-15 22:20:09 +01:00
|
|
|
* @since Twenty Fourteen 1.0
|
|
|
|
*
|
2013-10-08 23:22:10 +02:00
|
|
|
* @return void
|
2013-10-16 01:24:10 +02:00
|
|
|
*/
|
|
|
|
function twentyfourteen_post_thumbnail() {
|
2013-11-19 00:11:10 +01:00
|
|
|
if ( post_password_required() || ! has_post_thumbnail() ) {
|
2013-10-16 01:24:10 +02:00
|
|
|
return;
|
2013-11-19 00:11:10 +01:00
|
|
|
}
|
2013-10-16 01:24:10 +02:00
|
|
|
|
|
|
|
if ( is_singular() ) :
|
|
|
|
?>
|
|
|
|
|
2013-10-30 15:39:10 +01:00
|
|
|
<div class="post-thumbnail">
|
2013-11-07 18:29:10 +01:00
|
|
|
<?php
|
2013-12-04 04:29:10 +01:00
|
|
|
if ( ( ! is_active_sidebar( 'sidebar-2' ) || is_page_template( 'page-templates/full-width.php' ) ) ) {
|
2013-11-14 05:50:11 +01:00
|
|
|
the_post_thumbnail( 'twentyfourteen-full-width' );
|
2013-11-19 00:11:10 +01:00
|
|
|
} else {
|
2013-11-14 05:50:11 +01:00
|
|
|
the_post_thumbnail();
|
2013-11-19 00:11:10 +01:00
|
|
|
}
|
2013-11-07 18:29:10 +01:00
|
|
|
?>
|
2013-10-16 01:24:10 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<?php else : ?>
|
|
|
|
|
2013-10-30 15:39:10 +01:00
|
|
|
<a class="post-thumbnail" href="<?php the_permalink(); ?>" rel="<?php the_ID(); ?>">
|
2013-11-07 18:29:10 +01:00
|
|
|
<?php
|
2013-12-04 04:29:10 +01:00
|
|
|
if ( ( ! is_active_sidebar( 'sidebar-2' ) || is_page_template( 'page-templates/full-width.php' ) ) ) {
|
2013-11-14 05:50:11 +01:00
|
|
|
the_post_thumbnail( 'twentyfourteen-full-width' );
|
2013-11-19 00:11:10 +01:00
|
|
|
} else {
|
2013-11-14 05:50:11 +01:00
|
|
|
the_post_thumbnail();
|
2013-11-19 00:11:10 +01:00
|
|
|
}
|
2013-11-07 18:29:10 +01:00
|
|
|
?>
|
2013-10-16 01:24:10 +02:00
|
|
|
</a>
|
|
|
|
|
|
|
|
<?php endif; // End is_singular()
|
|
|
|
}
|