]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-content/themes/twentyfourteen/inc/template-tags.php
WordPress 4.2-scripts
[autoinstalls/wordpress.git] / wp-content / themes / twentyfourteen / inc / template-tags.php
1 <?php
2 /**
3  * Custom template tags for Twenty Fourteen
4  *
5  * @package WordPress
6  * @subpackage Twenty_Fourteen
7  * @since Twenty Fourteen 1.0
8  */
9
10 if ( ! function_exists( 'twentyfourteen_paging_nav' ) ) :
11 /**
12  * Display navigation to next/previous set of posts when applicable.
13  *
14  * @since Twenty Fourteen 1.0
15  *
16  * @global WP_Query   $wp_query   WordPress Query object.
17  * @global WP_Rewrite $wp_rewrite WordPress Rewrite object.
18  */
19 function twentyfourteen_paging_nav() {
20         global $wp_query, $wp_rewrite;
21
22         // Don't print empty markup if there's only one page.
23         if ( $wp_query->max_num_pages < 2 ) {
24                 return;
25         }
26
27         $paged        = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1;
28         $pagenum_link = html_entity_decode( get_pagenum_link() );
29         $query_args   = array();
30         $url_parts    = explode( '?', $pagenum_link );
31
32         if ( isset( $url_parts[1] ) ) {
33                 wp_parse_str( $url_parts[1], $query_args );
34         }
35
36         $pagenum_link = remove_query_arg( array_keys( $query_args ), $pagenum_link );
37         $pagenum_link = trailingslashit( $pagenum_link ) . '%_%';
38
39         $format  = $wp_rewrite->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : '';
40         $format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?paged=%#%';
41
42         // Set up paginated links.
43         $links = paginate_links( array(
44                 'base'     => $pagenum_link,
45                 'format'   => $format,
46                 'total'    => $wp_query->max_num_pages,
47                 'current'  => $paged,
48                 'mid_size' => 1,
49                 'add_args' => array_map( 'urlencode', $query_args ),
50                 'prev_text' => __( '&larr; Previous', 'twentyfourteen' ),
51                 'next_text' => __( 'Next &rarr;', 'twentyfourteen' ),
52         ) );
53
54         if ( $links ) :
55
56         ?>
57         <nav class="navigation paging-navigation" role="navigation">
58                 <h1 class="screen-reader-text"><?php _e( 'Posts navigation', 'twentyfourteen' ); ?></h1>
59                 <div class="pagination loop-pagination">
60                         <?php echo $links; ?>
61                 </div><!-- .pagination -->
62         </nav><!-- .navigation -->
63         <?php
64         endif;
65 }
66 endif;
67
68 if ( ! function_exists( 'twentyfourteen_post_nav' ) ) :
69 /**
70  * Display navigation to next/previous post when applicable.
71  *
72  * @since Twenty Fourteen 1.0
73  */
74 function twentyfourteen_post_nav() {
75         // Don't print empty markup if there's nowhere to navigate.
76         $previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
77         $next     = get_adjacent_post( false, '', false );
78
79         if ( ! $next && ! $previous ) {
80                 return;
81         }
82
83         ?>
84         <nav class="navigation post-navigation" role="navigation">
85                 <h1 class="screen-reader-text"><?php _e( 'Post navigation', 'twentyfourteen' ); ?></h1>
86                 <div class="nav-links">
87                         <?php
88                         if ( is_attachment() ) :
89                                 previous_post_link( '%link', __( '<span class="meta-nav">Published In</span>%title', 'twentyfourteen' ) );
90                         else :
91                                 previous_post_link( '%link', __( '<span class="meta-nav">Previous Post</span>%title', 'twentyfourteen' ) );
92                                 next_post_link( '%link', __( '<span class="meta-nav">Next Post</span>%title', 'twentyfourteen' ) );
93                         endif;
94                         ?>
95                 </div><!-- .nav-links -->
96         </nav><!-- .navigation -->
97         <?php
98 }
99 endif;
100
101 if ( ! function_exists( 'twentyfourteen_posted_on' ) ) :
102 /**
103  * Print HTML with meta information for the current post-date/time and author.
104  *
105  * @since Twenty Fourteen 1.0
106  */
107 function twentyfourteen_posted_on() {
108         if ( is_sticky() && is_home() && ! is_paged() ) {
109                 echo '<span class="featured-post">' . __( 'Sticky', 'twentyfourteen' ) . '</span>';
110         }
111
112         // Set up and print post meta information.
113         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>',
114                 esc_url( get_permalink() ),
115                 esc_attr( get_the_date( 'c' ) ),
116                 esc_html( get_the_date() ),
117                 esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
118                 get_the_author()
119         );
120 }
121 endif;
122
123 /**
124  * Find out if blog has more than one category.
125  *
126  * @since Twenty Fourteen 1.0
127  *
128  * @return boolean true if blog has more than 1 category
129  */
130 function twentyfourteen_categorized_blog() {
131         if ( false === ( $all_the_cool_cats = get_transient( 'twentyfourteen_category_count' ) ) ) {
132                 // Create an array of all the categories that are attached to posts
133                 $all_the_cool_cats = get_categories( array(
134                         'hide_empty' => 1,
135                 ) );
136
137                 // Count the number of categories that are attached to the posts
138                 $all_the_cool_cats = count( $all_the_cool_cats );
139
140                 set_transient( 'twentyfourteen_category_count', $all_the_cool_cats );
141         }
142
143         if ( 1 !== (int) $all_the_cool_cats ) {
144                 // This blog has more than 1 category so twentyfourteen_categorized_blog should return true
145                 return true;
146         } else {
147                 // This blog has only 1 category so twentyfourteen_categorized_blog should return false
148                 return false;
149         }
150 }
151
152 /**
153  * Flush out the transients used in twentyfourteen_categorized_blog.
154  *
155  * @since Twenty Fourteen 1.0
156  */
157 function twentyfourteen_category_transient_flusher() {
158         // Like, beat it. Dig?
159         delete_transient( 'twentyfourteen_category_count' );
160 }
161 add_action( 'edit_category', 'twentyfourteen_category_transient_flusher' );
162 add_action( 'save_post',     'twentyfourteen_category_transient_flusher' );
163
164 if ( ! function_exists( 'twentyfourteen_post_thumbnail' ) ) :
165 /**
166  * Display an optional post thumbnail.
167  *
168  * Wraps the post thumbnail in an anchor element on index
169  * views, or a div element when on single views.
170  *
171  * @since Twenty Fourteen 1.0
172  * @since Twenty Fourteen 1.4 Was made 'pluggable', or overridable.
173  */
174 function twentyfourteen_post_thumbnail() {
175         if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) {
176                 return;
177         }
178
179         if ( is_singular() ) :
180         ?>
181
182         <div class="post-thumbnail">
183         <?php
184                 if ( ( ! is_active_sidebar( 'sidebar-2' ) || is_page_template( 'page-templates/full-width.php' ) ) ) {
185                         the_post_thumbnail( 'twentyfourteen-full-width' );
186                 } else {
187                         the_post_thumbnail();
188                 }
189         ?>
190         </div>
191
192         <?php else : ?>
193
194         <a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true">
195         <?php
196                 if ( ( ! is_active_sidebar( 'sidebar-2' ) || is_page_template( 'page-templates/full-width.php' ) ) ) {
197                         the_post_thumbnail( 'twentyfourteen-full-width' );
198                 } else {
199                         the_post_thumbnail( 'post-thumbnail', array( 'alt' => get_the_title() ) );
200                 }
201         ?>
202         </a>
203
204         <?php endif; // End is_singular()
205 }
206 endif;
207
208 if ( ! function_exists( 'twentyfourteen_excerpt_more' ) && ! is_admin() ) :
209 /**
210  * Replaces "[...]" (appended to automatically generated excerpts) with ...
211  * and a Continue reading link.
212  *
213  * @since Twenty Fourteen 1.3
214  *
215  * @param string $more Default Read More excerpt link.
216  * @return string Filtered Read More excerpt link.
217  */
218 function twentyfourteen_excerpt_more( $more ) {
219         $link = sprintf( '<a href="%1$s" class="more-link">%2$s</a>',
220                 esc_url( get_permalink( get_the_ID() ) ),
221                         /* translators: %s: Name of current post */
222                         sprintf( __( 'Continue reading %s <span class="meta-nav">&rarr;</span>', 'twentyfourteen' ), '<span class="screen-reader-text">' . get_the_title( get_the_ID() ) . '</span>' )
223                 );
224         return ' &hellip; ' . $link;
225 }
226 add_filter( 'excerpt_more', 'twentyfourteen_excerpt_more' );
227 endif;