PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/inc/template-tags.php

https://github.com/dhigginbotham/_s
PHP | 175 lines | 108 code | 24 blank | 43 comment | 24 complexity | 4e749c2a15be7a0f906a7e40074702d9 MD5 | raw file
Possible License(s): AGPL-1.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 _s
  8. * @since _s 1.0
  9. */
  10. if ( ! function_exists( '_s_content_nav' ) ) :
  11. /**
  12. * Display navigation to next/previous pages when applicable
  13. *
  14. * @since _s 1.0
  15. */
  16. function _s_content_nav( $nav_id ) {
  17. global $wp_query, $post;
  18. // Don't print empty markup on single pages if there's nowhere to navigate.
  19. if ( is_single() ) {
  20. $previous = ( is_attachment() ) ? get_post( $post->post_parent ) : get_adjacent_post( false, '', true );
  21. $next = get_adjacent_post( false, '', false );
  22. if ( ! $next && ! $previous )
  23. return;
  24. }
  25. // Don't print empty markup in archives if there's only one page.
  26. if ( $wp_query->max_num_pages < 2 && ( is_home() || is_archive() || is_search() ) )
  27. return;
  28. $nav_class = 'site-navigation paging-navigation';
  29. if ( is_single() )
  30. $nav_class = 'site-navigation post-navigation';
  31. ?>
  32. <nav role="navigation" id="<?php echo $nav_id; ?>" class="<?php echo $nav_class; ?>">
  33. <h1 class="assistive-text"><?php _e( 'Post navigation', '_s' ); ?></h1>
  34. <?php if ( is_single() ) : // navigation links for single posts ?>
  35. <?php previous_post_link( '<div class="nav-previous">%link</div>', '<span class="meta-nav">' . _x( '&larr;', 'Previous post link', '_s' ) . '</span> %title' ); ?>
  36. <?php next_post_link( '<div class="nav-next">%link</div>', '%title <span class="meta-nav">' . _x( '&rarr;', 'Next post link', '_s' ) . '</span>' ); ?>
  37. <?php elseif ( $wp_query->max_num_pages > 1 && ( is_home() || is_archive() || is_search() ) ) : // navigation links for home, archive, and search pages ?>
  38. <?php if ( get_next_posts_link() ) : ?>
  39. <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', '_s' ) ); ?></div>
  40. <?php endif; ?>
  41. <?php if ( get_previous_posts_link() ) : ?>
  42. <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', '_s' ) ); ?></div>
  43. <?php endif; ?>
  44. <?php endif; ?>
  45. </nav><!-- #<?php echo $nav_id; ?> -->
  46. <?php
  47. }
  48. endif; // _s_content_nav
  49. if ( ! function_exists( '_s_comment' ) ) :
  50. /**
  51. * Template for comments and pingbacks.
  52. *
  53. * Used as a callback by wp_list_comments() for displaying the comments.
  54. *
  55. * @since _s 1.0
  56. */
  57. function _s_comment( $comment, $args, $depth ) {
  58. $GLOBALS['comment'] = $comment;
  59. switch ( $comment->comment_type ) :
  60. case 'pingback' :
  61. case 'trackback' :
  62. ?>
  63. <li class="post pingback">
  64. <p><?php _e( 'Pingback:', '_s' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( '(Edit)', '_s' ), ' ' ); ?></p>
  65. <?php
  66. break;
  67. default :
  68. ?>
  69. <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
  70. <article id="comment-<?php comment_ID(); ?>" class="comment">
  71. <footer>
  72. <div class="comment-author vcard">
  73. <?php echo get_avatar( $comment, 40 ); ?>
  74. <?php printf( __( '%s <span class="says">says:</span>', '_s' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
  75. </div><!-- .comment-author .vcard -->
  76. <?php if ( $comment->comment_approved == '0' ) : ?>
  77. <em><?php _e( 'Your comment is awaiting moderation.', '_s' ); ?></em>
  78. <br />
  79. <?php endif; ?>
  80. <div class="comment-meta commentmetadata">
  81. <a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>"><time pubdate datetime="<?php comment_time( 'c' ); ?>">
  82. <?php
  83. /* translators: 1: date, 2: time */
  84. printf( __( '%1$s at %2$s', '_s' ), get_comment_date(), get_comment_time() ); ?>
  85. </time></a>
  86. <?php edit_comment_link( __( '(Edit)', '_s' ), ' ' );
  87. ?>
  88. </div><!-- .comment-meta .commentmetadata -->
  89. </footer>
  90. <div class="comment-content"><?php comment_text(); ?></div>
  91. <div class="reply">
  92. <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
  93. </div><!-- .reply -->
  94. </article><!-- #comment-## -->
  95. <?php
  96. break;
  97. endswitch;
  98. }
  99. endif; // ends check for _s_comment()
  100. if ( ! function_exists( '_s_posted_on' ) ) :
  101. /**
  102. * Prints HTML with meta information for the current post-date/time and author.
  103. *
  104. * @since _s 1.0
  105. */
  106. function _s_posted_on() {
  107. printf( __( 'Posted on <a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s" pubdate>%4$s</time></a><span class="byline"> by <span class="author vcard"><a class="url fn n" href="%5$s" title="%6$s" rel="author">%7$s</a></span></span>', '_s' ),
  108. esc_url( get_permalink() ),
  109. esc_attr( get_the_time() ),
  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. esc_attr( sprintf( __( 'View all posts by %s', '_s' ), get_the_author() ) ),
  114. esc_html( get_the_author() )
  115. );
  116. }
  117. endif;
  118. /**
  119. * Returns true if a blog has more than 1 category
  120. *
  121. * @since _s 1.0
  122. */
  123. function _s_categorized_blog() {
  124. if ( false === ( $all_the_cool_cats = get_transient( 'all_the_cool_cats' ) ) ) {
  125. // Create an array of all the categories that are attached to posts
  126. $all_the_cool_cats = get_categories( array(
  127. 'hide_empty' => 1,
  128. ) );
  129. // Count the number of categories that are attached to the posts
  130. $all_the_cool_cats = count( $all_the_cool_cats );
  131. set_transient( 'all_the_cool_cats', $all_the_cool_cats );
  132. }
  133. if ( '1' != $all_the_cool_cats ) {
  134. // This blog has more than 1 category so _s_categorized_blog should return true
  135. return true;
  136. } else {
  137. // This blog has only 1 category so _s_categorized_blog should return false
  138. return false;
  139. }
  140. }
  141. /**
  142. * Flush out the transients used in _s_categorized_blog
  143. *
  144. * @since _s 1.0
  145. */
  146. function _s_category_transient_flusher() {
  147. // Like, beat it. Dig?
  148. delete_transient( 'all_the_cool_cats' );
  149. }
  150. add_action( 'edit_category', '_s_category_transient_flusher' );
  151. add_action( 'save_post', '_s_category_transient_flusher' );