]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-content/themes/twentyfourteen/inc/template-tags.php
WordPress 3.9
[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 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 ) {
19                 return;
20         }
21
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 );
26
27         if ( isset( $url_parts[1] ) ) {
28                 wp_parse_str( $url_parts[1], $query_args );
29         }
30
31         $pagenum_link = remove_query_arg( array_keys( $query_args ), $pagenum_link );
32         $pagenum_link = trailingslashit( $pagenum_link ) . '%_%';
33
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=%#%';
36
37         // Set up paginated links.
38         $links = paginate_links( array(
39                 'base'     => $pagenum_link,
40                 'format'   => $format,
41                 'total'    => $GLOBALS['wp_query']->max_num_pages,
42                 'current'  => $paged,
43                 'mid_size' => 1,
44                 'add_args' => array_map( 'urlencode', $query_args ),
45                 'prev_text' => __( '&larr; Previous', 'twentyfourteen' ),
46                 'next_text' => __( 'Next &rarr;', 'twentyfourteen' ),
47         ) );
48
49         if ( $links ) :
50
51         ?>
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">
55                         <?php echo $links; ?>
56                 </div><!-- .pagination -->
57         </nav><!-- .navigation -->
58         <?php
59         endif;
60 }
61 endif;
62
63 if ( ! function_exists( 'twentyfourteen_post_nav' ) ) :
64 /**
65  * Display navigation to next/previous post when applicable.
66  *
67  * @since Twenty Fourteen 1.0
68  */
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 );
73
74         if ( ! $next && ! $previous ) {
75                 return;
76         }
77
78         ?>
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">
82                         <?php
83                         if ( is_attachment() ) :
84                                 previous_post_link( '%link', __( '<span class="meta-nav">Published In</span>%title', 'twentyfourteen' ) );
85                         else :
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' ) );
88                         endif;
89                         ?>
90                 </div><!-- .nav-links -->
91         </nav><!-- .navigation -->
92         <?php
93 }
94 endif;
95
96 if ( ! function_exists( 'twentyfourteen_posted_on' ) ) :
97 /**
98  * Print HTML with meta information for the current post-date/time and author.
99  *
100  * @since Twenty Fourteen 1.0
101  */
102 function twentyfourteen_posted_on() {
103         if ( is_sticky() && is_home() && ! is_paged() ) {
104                 echo '<span class="featured-post">' . __( 'Sticky', 'twentyfourteen' ) . '</span>';
105         }
106
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' ) ) ),
113                 get_the_author()
114         );
115 }
116 endif;
117
118 /**
119  * Find out if blog has more than one category.
120  *
121  * @since Twenty Fourteen 1.0
122  *
123  * @return boolean true if blog has more than 1 category
124  */
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(
129                         'hide_empty' => 1,
130                 ) );
131
132                 // Count the number of categories that are attached to the posts
133                 $all_the_cool_cats = count( $all_the_cool_cats );
134
135                 set_transient( 'twentyfourteen_category_count', $all_the_cool_cats );
136         }
137
138         if ( 1 !== (int) $all_the_cool_cats ) {
139                 // This blog has more than 1 category so twentyfourteen_categorized_blog should return true
140                 return true;
141         } else {
142                 // This blog has only 1 category so twentyfourteen_categorized_blog should return false
143                 return false;
144         }
145 }
146
147 /**
148  * Flush out the transients used in twentyfourteen_categorized_blog.
149  *
150  * @since Twenty Fourteen 1.0
151  */
152 function twentyfourteen_category_transient_flusher() {
153         // Like, beat it. Dig?
154         delete_transient( 'twentyfourteen_category_count' );
155 }
156 add_action( 'edit_category', 'twentyfourteen_category_transient_flusher' );
157 add_action( 'save_post',     'twentyfourteen_category_transient_flusher' );
158
159 /**
160  * Display an optional post thumbnail.
161  *
162  * Wraps the post thumbnail in an anchor element on index
163  * views, or a div element when on single views.
164  *
165  * @since Twenty Fourteen 1.0
166  */
167 function twentyfourteen_post_thumbnail() {
168         if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) {
169                 return;
170         }
171
172         if ( is_singular() ) :
173         ?>
174
175         <div class="post-thumbnail">
176         <?php
177                 if ( ( ! is_active_sidebar( 'sidebar-2' ) || is_page_template( 'page-templates/full-width.php' ) ) ) {
178                         the_post_thumbnail( 'twentyfourteen-full-width' );
179                 } else {
180                         the_post_thumbnail();
181                 }
182         ?>
183         </div>
184
185         <?php else : ?>
186
187         <a class="post-thumbnail" href="<?php the_permalink(); ?>">
188         <?php
189                 if ( ( ! is_active_sidebar( 'sidebar-2' ) || is_page_template( 'page-templates/full-width.php' ) ) ) {
190                         the_post_thumbnail( 'twentyfourteen-full-width' );
191                 } else {
192                         the_post_thumbnail();
193                 }
194         ?>
195         </a>
196
197         <?php endif; // End is_singular()
198 }