PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/inc/template-tags.php

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