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
18 function twentyfourteen_paging_nav() {
19 // Don't print empty markup if there's only one page.
20 if ( $GLOBALS['wp_query']->max_num_pages < 2 ) {
24 $paged = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1;
25 $pagenum_link = html_entity_decode( get_pagenum_link() );
26 $query_args = array();
27 $url_parts = explode( '?', $pagenum_link );
29 if ( isset( $url_parts[1] ) ) {
30 wp_parse_str( $url_parts[1], $query_args );
33 $pagenum_link = remove_query_arg( array_keys( $query_args ), $pagenum_link );
34 $pagenum_link = trailingslashit( $pagenum_link ) . '%_%';
36 $format = $GLOBALS['wp_rewrite']->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : '';
37 $format .= $GLOBALS['wp_rewrite']->using_permalinks() ? user_trailingslashit( 'page/%#%', 'paged' ) : '?paged=%#%';
39 // Set up paginated links.
40 $links = paginate_links( array(
41 'base' => $pagenum_link,
43 'total' => $GLOBALS['wp_query']->max_num_pages,
46 'add_args' => array_map( 'urlencode', $query_args ),
47 'prev_text' => __( '← Previous', 'twentyfourteen' ),
48 'next_text' => __( 'Next →', 'twentyfourteen' ),
54 <nav class="navigation paging-navigation" role="navigation">
55 <h1 class="screen-reader-text"><?php _e( 'Posts navigation', 'twentyfourteen' ); ?></h1>
56 <div class="pagination loop-pagination">
58 </div><!-- .pagination -->
59 </nav><!-- .navigation -->
65 if ( ! function_exists( 'twentyfourteen_post_nav' ) ) :
67 * Display navigation to next/previous post when applicable.
69 * @since Twenty Fourteen 1.0
73 function twentyfourteen_post_nav() {
74 // Don't print empty markup if there's nowhere to navigate.
75 $previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
76 $next = get_adjacent_post( false, '', false );
78 if ( ! $next && ! $previous ) {
83 <nav class="navigation post-navigation" role="navigation">
84 <h1 class="screen-reader-text"><?php _e( 'Post navigation', 'twentyfourteen' ); ?></h1>
85 <div class="nav-links">
87 if ( is_attachment() ) :
88 previous_post_link( '%link', __( '<span class="meta-nav">Published In</span>%title', 'twentyfourteen' ) );
90 previous_post_link( '%link', __( '<span class="meta-nav">Previous Post</span>%title', 'twentyfourteen' ) );
91 next_post_link( '%link', __( '<span class="meta-nav">Next Post</span>%title', 'twentyfourteen' ) );
94 </div><!-- .nav-links -->
95 </nav><!-- .navigation -->
100 if ( ! function_exists( 'twentyfourteen_posted_on' ) ) :
102 * Print HTML with meta information for the current post-date/time and author.
104 * @since Twenty Fourteen 1.0
108 function twentyfourteen_posted_on() {
109 if ( is_sticky() && is_home() && ! is_paged() ) {
110 echo '<span class="featured-post">' . __( 'Sticky', 'twentyfourteen' ) . '</span>';
113 // Set up and print post meta information.
114 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>',
115 esc_url( get_permalink() ),
116 esc_attr( get_the_date( 'c' ) ),
117 esc_html( get_the_date() ),
118 esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
125 * Find out if blog has more than one category.
127 * @since Twenty Fourteen 1.0
129 * @return boolean true if blog has more than 1 category
131 function twentyfourteen_categorized_blog() {
132 if ( false === ( $all_the_cool_cats = get_transient( 'twentyfourteen_category_count' ) ) ) {
133 // Create an array of all the categories that are attached to posts
134 $all_the_cool_cats = get_categories( array(
138 // Count the number of categories that are attached to the posts
139 $all_the_cool_cats = count( $all_the_cool_cats );
141 set_transient( 'twentyfourteen_category_count', $all_the_cool_cats );
144 if ( 1 !== (int) $all_the_cool_cats ) {
145 // This blog has more than 1 category so twentyfourteen_categorized_blog should return true
148 // This blog has only 1 category so twentyfourteen_categorized_blog should return false
154 * Flush out the transients used in twentyfourteen_categorized_blog.
156 * @since Twenty Fourteen 1.0
160 function twentyfourteen_category_transient_flusher() {
161 // Like, beat it. Dig?
162 delete_transient( 'twentyfourteen_category_count' );
164 add_action( 'edit_category', 'twentyfourteen_category_transient_flusher' );
165 add_action( 'save_post', 'twentyfourteen_category_transient_flusher' );
168 * Display an optional post thumbnail.
170 * Wraps the post thumbnail in an anchor element on index
171 * views, or a div element when on single views.
173 * @since Twenty Fourteen 1.0
177 function twentyfourteen_post_thumbnail() {
178 if ( post_password_required() || ! has_post_thumbnail() ) {
182 if ( is_singular() ) :
185 <div class="post-thumbnail">
187 if ( ( ! is_active_sidebar( 'sidebar-2' ) || is_page_template( 'page-templates/full-width.php' ) ) ) {
188 the_post_thumbnail( 'twentyfourteen-full-width' );
190 the_post_thumbnail();
197 <a class="post-thumbnail" href="<?php the_permalink(); ?>">
199 if ( ( ! is_active_sidebar( 'sidebar-2' ) || is_page_template( 'page-templates/full-width.php' ) ) ) {
200 the_post_thumbnail( 'twentyfourteen-full-width' );
202 the_post_thumbnail();
207 <?php endif; // End is_singular()