3 * Custom template tags for Twenty Fourteen
6 * @subpackage Twenty_Fourteen
7 * @since Twenty Fourteen 1.0
10 if ( ! function_exists( 'twentyfourteen_paging_nav' ) ) :
12 * Display navigation to next/previous set of posts when applicable.
14 * @since Twenty Fourteen 1.0
16 function twentyfourteen_paging_nav() {
17 // Don't print empty markup if there's only one page.
18 if ( $GLOBALS['wp_query']->max_num_pages < 2 ) {
22 $paged = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1;
23 $pagenum_link = html_entity_decode( get_pagenum_link() );
24 $query_args = array();
25 $url_parts = explode( '?', $pagenum_link );
27 if ( isset( $url_parts[1] ) ) {
28 wp_parse_str( $url_parts[1], $query_args );
31 $pagenum_link = remove_query_arg( array_keys( $query_args ), $pagenum_link );
32 $pagenum_link = trailingslashit( $pagenum_link ) . '%_%';
34 $format = $GLOBALS['wp_rewrite']->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : '';
35 $format .= $GLOBALS['wp_rewrite']->using_permalinks() ? user_trailingslashit( 'page/%#%', 'paged' ) : '?paged=%#%';
37 // Set up paginated links.
38 $links = paginate_links( array(
39 'base' => $pagenum_link,
41 'total' => $GLOBALS['wp_query']->max_num_pages,
44 'add_args' => array_map( 'urlencode', $query_args ),
45 'prev_text' => __( '← Previous', 'twentyfourteen' ),
46 'next_text' => __( 'Next →', 'twentyfourteen' ),
52 <nav class="navigation paging-navigation" role="navigation">
53 <h1 class="screen-reader-text"><?php _e( 'Posts navigation', 'twentyfourteen' ); ?></h1>
54 <div class="pagination loop-pagination">
56 </div><!-- .pagination -->
57 </nav><!-- .navigation -->
63 if ( ! function_exists( 'twentyfourteen_post_nav' ) ) :
65 * Display navigation to next/previous post when applicable.
67 * @since Twenty Fourteen 1.0
69 function twentyfourteen_post_nav() {
70 // Don't print empty markup if there's nowhere to navigate.
71 $previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
72 $next = get_adjacent_post( false, '', false );
74 if ( ! $next && ! $previous ) {
79 <nav class="navigation post-navigation" role="navigation">
80 <h1 class="screen-reader-text"><?php _e( 'Post navigation', 'twentyfourteen' ); ?></h1>
81 <div class="nav-links">
83 if ( is_attachment() ) :
84 previous_post_link( '%link', __( '<span class="meta-nav">Published In</span>%title', 'twentyfourteen' ) );
86 previous_post_link( '%link', __( '<span class="meta-nav">Previous Post</span>%title', 'twentyfourteen' ) );
87 next_post_link( '%link', __( '<span class="meta-nav">Next Post</span>%title', 'twentyfourteen' ) );
90 </div><!-- .nav-links -->
91 </nav><!-- .navigation -->
96 if ( ! function_exists( 'twentyfourteen_posted_on' ) ) :
98 * Print HTML with meta information for the current post-date/time and author.
100 * @since Twenty Fourteen 1.0
102 function twentyfourteen_posted_on() {
103 if ( is_sticky() && is_home() && ! is_paged() ) {
104 echo '<span class="featured-post">' . __( 'Sticky', 'twentyfourteen' ) . '</span>';
107 // Set up and print post meta information.
108 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>',
109 esc_url( get_permalink() ),
110 esc_attr( get_the_date( 'c' ) ),
111 esc_html( get_the_date() ),
112 esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
119 * Find out if blog has more than one category.
121 * @since Twenty Fourteen 1.0
123 * @return boolean true if blog has more than 1 category
125 function twentyfourteen_categorized_blog() {
126 if ( false === ( $all_the_cool_cats = get_transient( 'twentyfourteen_category_count' ) ) ) {
127 // Create an array of all the categories that are attached to posts
128 $all_the_cool_cats = get_categories( array(
132 // Count the number of categories that are attached to the posts
133 $all_the_cool_cats = count( $all_the_cool_cats );
135 set_transient( 'twentyfourteen_category_count', $all_the_cool_cats );
138 if ( 1 !== (int) $all_the_cool_cats ) {
139 // This blog has more than 1 category so twentyfourteen_categorized_blog should return true
142 // This blog has only 1 category so twentyfourteen_categorized_blog should return false
148 * Flush out the transients used in twentyfourteen_categorized_blog.
150 * @since Twenty Fourteen 1.0
152 function twentyfourteen_category_transient_flusher() {
153 // Like, beat it. Dig?
154 delete_transient( 'twentyfourteen_category_count' );
156 add_action( 'edit_category', 'twentyfourteen_category_transient_flusher' );
157 add_action( 'save_post', 'twentyfourteen_category_transient_flusher' );
160 * Display an optional post thumbnail.
162 * Wraps the post thumbnail in an anchor element on index
163 * views, or a div element when on single views.
165 * @since Twenty Fourteen 1.0
167 function twentyfourteen_post_thumbnail() {
168 if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) {
172 if ( is_singular() ) :
175 <div class="post-thumbnail">
177 if ( ( ! is_active_sidebar( 'sidebar-2' ) || is_page_template( 'page-templates/full-width.php' ) ) ) {
178 the_post_thumbnail( 'twentyfourteen-full-width' );
180 the_post_thumbnail();
187 <a class="post-thumbnail" href="<?php the_permalink(); ?>">
189 if ( ( ! is_active_sidebar( 'sidebar-2' ) || is_page_template( 'page-templates/full-width.php' ) ) ) {
190 the_post_thumbnail( 'twentyfourteen-full-width' );
192 the_post_thumbnail();
197 <?php endif; // End is_singular()