Advertisement
Guest User

Untitled

a guest
Mar 25th, 2015
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.93 KB | None | 0 0
  1. <?php
  2. /**
  3. * Custom template tags for this theme.
  4. *
  5. * Eventually, some of the functionality here could be replaced by core features
  6. *
  7. * @package Sixteen
  8. */
  9.  
  10. if ( ! function_exists( 'sixteen_content_nav' ) ) :
  11. /**
  12. * Display navigation to next/previous pages when applicable
  13. */
  14. function sixteen_content_nav( $nav_id ) {
  15. global $wp_query, $post;
  16.  
  17. // Don't print empty markup on single pages if there's nowhere to navigate.
  18. if ( is_single() ) {
  19. $previous = ( is_attachment() ) ? get_post( $post->post_parent ) : get_adjacent_post( false, '', true );
  20. $next = get_adjacent_post( false, '', false );
  21.  
  22. if ( ! $next && ! $previous )
  23. return;
  24. }
  25.  
  26. // Don't print empty markup in archives if there's only one page.
  27. if ( $wp_query->max_num_pages < 2 && ( is_home() || is_archive() || is_search() ) )
  28. return;
  29.  
  30. $nav_class = ( is_single() ) ? 'post-navigation' : 'paging-navigation';
  31.  
  32. ?>
  33. <nav role="navigation" id="<?php echo esc_attr( $nav_id ); ?>" class="<?php echo $nav_class; ?>">
  34. <h1 class="screen-reader-text"><?php _e( 'Post navigation', 'sixteen' ); ?></h1>
  35.  
  36. <?php if ( is_single() ) : // navigation links for single posts ?>
  37.  
  38. <?php previous_post_link ( '&larr; %link', '%title', true, '', 'category' ); ?>
  39. <?php next_post_link ( '%link &rarr;', '%title', true, '', 'category' ); ?>
  40.  
  41. <?php elseif ( $wp_query->max_num_pages > 1 && ( is_home() || is_archive() || is_search() ) ) : // navigation links for home, archive, and search pages ?>
  42.  
  43. <?php if ( get_next_posts_link() ) : ?>
  44. <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'sixteen' ) ); ?></div>
  45. <?php endif; ?>
  46.  
  47. <?php if ( get_previous_posts_link() ) : ?>
  48. <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'sixteen' ) ); ?></div>
  49. <?php endif; ?>
  50.  
  51. <?php endif; ?>
  52.  
  53. </nav><!-- #<?php echo esc_html( $nav_id ); ?> -->
  54. <?php
  55. }
  56. endif; // sixteen_content_nav
  57.  
  58. if ( ! function_exists( 'sixteen_comment' ) ) :
  59. /**
  60. * Template for comments and pingbacks.
  61. *
  62. * Used as a callback by wp_list_comments() for displaying the comments.
  63. */
  64. function sixteen_comment( $comment, $args, $depth ) {
  65. $GLOBALS['comment'] = $comment;
  66.  
  67. if ( 'pingback' == $comment->comment_type || 'trackback' == $comment->comment_type ) : ?>
  68.  
  69. <li id="comment-<?php comment_ID(); ?>" <?php comment_class(); ?>>
  70. <div class="comment-body">
  71. <?php _e( 'Pingback:', 'sixteen' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( 'Edit', 'sixteen' ), '<span class="edit-link">', '</span>' ); ?>
  72. </div>
  73.  
  74. <?php else : ?>
  75.  
  76. <li id="comment-<?php comment_ID(); ?>" <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ); ?>>
  77. <article id="div-comment-<?php comment_ID(); ?>" class="comment-body">
  78. <footer class="comment-meta">
  79. <div class="comment-author vcard">
  80. <?php if ( 0 != $args['avatar_size'] ) echo get_avatar( $comment, 150 ); ?>
  81. </div><!-- .comment-author -->
  82.  
  83. <div class="comment-metadata">
  84. <?php printf( __( sprintf( '<cite class="fn">%s</cite> on', get_comment_author_link() ) ) ); ?>
  85. <a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
  86. <time datetime="<?php comment_time( 'c' ); ?>">
  87. <?php printf( _x( '%1$s', '1: date', 'sixteen' ), get_comment_date(), get_comment_time() ); ?>
  88. </time>
  89. </a>
  90. <?php edit_comment_link( __( 'Edit', 'sixteen' ), '<span class="edit-link">', '</span>' ); ?>
  91. </div><!-- .comment-metadata -->
  92.  
  93. <?php if ( '0' == $comment->comment_approved ) : ?>
  94. <p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'sixteen' ); ?></p>
  95. <?php endif; ?>
  96. </footer><!-- .comment-meta -->
  97.  
  98. <div class="comment-content">
  99. <?php comment_text(); ?>
  100. </div><!-- .comment-content -->
  101.  
  102. <?php
  103. comment_reply_link( array_merge( $args, array(
  104. 'add_below' => 'div-comment',
  105. 'depth' => $depth,
  106. 'max_depth' => $args['max_depth'],
  107. 'before' => '<div class="reply">',
  108. 'after' => '</div>',
  109. ) ) );
  110. ?>
  111. </article><!-- .comment-body -->
  112.  
  113. <?php
  114. endif;
  115. }
  116. endif; // ends check for sixteen_comment()
  117.  
  118. if ( ! function_exists( 'sixteen_the_attached_image' ) ) :
  119. /**
  120. * Prints the attached image with a link to the next attached image.
  121. */
  122. function sixteen_the_attached_image() {
  123. $post = get_post();
  124. $attachment_size = apply_filters( 'sixteen_attachment_size', array( 1200, 1200 ) );
  125. $next_attachment_url = wp_get_attachment_url();
  126.  
  127. /**
  128. * Grab the IDs of all the image attachments in a gallery so we can get the
  129. * URL of the next adjacent image in a gallery, or the first image (if
  130. * we're looking at the last image in a gallery), or, in a gallery of one,
  131. * just the link to that image file.
  132. */
  133. $attachment_ids = get_posts( array(
  134. 'post_parent' => $post->post_parent,
  135. 'fields' => 'ids',
  136. 'numberposts' => -1,
  137. 'post_status' => 'inherit',
  138. 'post_type' => 'attachment',
  139. 'post_mime_type' => 'image',
  140. 'order' => 'ASC',
  141. 'orderby' => 'menu_order ID'
  142. ) );
  143.  
  144. // If there is more than 1 attachment in a gallery...
  145. if ( count( $attachment_ids ) > 1 ) {
  146. foreach ( $attachment_ids as $attachment_id ) {
  147. if ( $attachment_id == $post->ID ) {
  148. $next_id = current( $attachment_ids );
  149. break;
  150. }
  151. }
  152.  
  153. // get the URL of the next image attachment...
  154. if ( $next_id )
  155. $next_attachment_url = get_attachment_link( $next_id );
  156.  
  157. // or get the URL of the first image attachment.
  158. else
  159. $next_attachment_url = get_attachment_link( array_shift( $attachment_ids ) );
  160. }
  161.  
  162. printf( '<a href="%1$s" rel="attachment">%2$s</a>',
  163. esc_url( $next_attachment_url ),
  164. wp_get_attachment_image( $post->ID, $attachment_size )
  165. );
  166. }
  167. endif;
  168.  
  169. if ( ! function_exists( 'sixteen_posted_on' ) ) :
  170. /**
  171. * Prints HTML with meta information for the current post-date/time and author.
  172. */
  173. function sixteen_posted_on() {
  174. $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>';
  175. if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) )
  176. $time_string .= '<time class="updated" datetime="%3$s">%4$s</time>';
  177.  
  178. $time_string = sprintf( $time_string,
  179. esc_attr( get_the_date( 'c' ) ),
  180. esc_html( get_the_date() ),
  181. esc_attr( get_the_modified_date( 'c' ) ),
  182. esc_html( get_the_modified_date() )
  183. );
  184.  
  185. printf( __( '<span class="posted-on">Published %1$s</span><span class="byline"> by %2$s</span>', 'sixteen' ),
  186. sprintf( '<a href="%1$s" rel="bookmark">%2$s</a>',
  187. esc_url( get_permalink() ),
  188. $time_string
  189. ),
  190. sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s">%2$s</a></span>',
  191. esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
  192. esc_html( get_the_author() )
  193. )
  194. );
  195. }
  196. endif;
  197.  
  198. /**
  199. * Returns true if a blog has more than 1 category
  200. */
  201. function sixteen_categorized_blog() {
  202. if ( false === ( $all_the_cool_cats = get_transient( 'all_the_cool_cats' ) ) ) {
  203. // Create an array of all the categories that are attached to posts
  204. $all_the_cool_cats = get_categories( array(
  205. 'hide_empty' => 1,
  206. ) );
  207.  
  208. // Count the number of categories that are attached to the posts
  209. $all_the_cool_cats = count( $all_the_cool_cats );
  210.  
  211. set_transient( 'all_the_cool_cats', $all_the_cool_cats );
  212. }
  213.  
  214. if ( '1' != $all_the_cool_cats ) {
  215. // This blog has more than 1 category so sixteen_categorized_blog should return true
  216. return true;
  217. } else {
  218. // This blog has only 1 category so sixteen_categorized_blog should return false
  219. return false;
  220. }
  221. }
  222.  
  223. /**
  224. * Flush out the transients used in sixteen_categorized_blog
  225. */
  226. function sixteen_category_transient_flusher() {
  227. // Like, beat it. Dig?
  228. delete_transient( 'all_the_cool_cats' );
  229. }
  230. add_action( 'edit_category', 'sixteen_category_transient_flusher' );
  231. add_action( 'save_post', 'sixteen_category_transient_flusher' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement