template-tags.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. if ( ! function_exists( '_ph_content_nav' ) ):
  3. function _ph_content_nav( $nav_id ) {
  4. global $wp_query;
  5. $nav_class = 'site-navigation paging-navigation';
  6. if ( is_single() )
  7. $nav_class = 'site-navigation post-navigation';
  8. ?>
  9. <nav role="navigation" id="<?php echo $nav_id; ?>" class="<?php echo $nav_class; ?>">
  10. <h1 class="assistive-text"><?php _e( 'Post navigation', '_ph' ); ?></h1>
  11. <?php if ( is_single() ) : // navigation links for single posts ?>
  12. <?php previous_post_link( '<div class="nav-previous">%link</div>', '<span class="meta-nav">' . _x( '&larr;', 'Previous post link', '_ph' ) . '</span> %title' ); ?>
  13. <?php next_post_link( '<div class="nav-next">%link</div>', '%title <span class="meta-nav">' . _x( '&rarr;', 'Next post link', '_ph' ) . '</span>' ); ?>
  14. <?php elseif ( $wp_query->max_num_pages > 1 && ( is_home() || is_archive() || is_search() ) ) : // navigation links for home, archive, and search pages ?>
  15. <?php if ( get_next_posts_link() ) : ?>
  16. <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', '_ph' ) ); ?></div>
  17. <?php endif; ?>
  18. <?php if ( get_previous_posts_link() ) : ?>
  19. <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', '_ph' ) ); ?></div>
  20. <?php endif; ?>
  21. <?php endif; ?>
  22. </nav><!-- #<?php echo $nav_id; ?> -->
  23. <?php
  24. }
  25. endif; // _ph_content_nav
  26. if ( ! function_exists( '_ph_comment' ) ) :
  27. function _ph_comment( $comment, $args, $depth ) {
  28. $GLOBALS['comment'] = $comment;
  29. switch ( $comment->comment_type ) :
  30. case 'pingback' :
  31. case 'trackback' :
  32. ?>
  33. <li class="post pingback">
  34. <p><?php _e( 'Pingback:', '_ph' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( '(Edit)', '_ph' ), ' ' ); ?></p>
  35. <?php
  36. break;
  37. default :
  38. ?>
  39. <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
  40. <article id="comment-<?php comment_ID(); ?>" class="comment">
  41. <footer>
  42. <div class="comment-author vcard">
  43. <?php echo get_avatar( $comment, 40 ); ?>
  44. <?php printf( __( '%s <span class="says">says:</span>', '_ph' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
  45. </div><!-- .comment-author .vcard -->
  46. <?php if ( $comment->comment_approved == '0' ) : ?>
  47. <em><?php _e( 'Your comment is awaiting moderation.', '_ph' ); ?></em>
  48. <br />
  49. <?php endif; ?>
  50. <div class="comment-meta commentmetadata">
  51. <a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>"><time pubdate datetime="<?php comment_time( 'c' ); ?>">
  52. <?php
  53. /* translators: 1: date, 2: time */
  54. printf( __( '%1$s at %2$s', '_ph' ), get_comment_date(), get_comment_time() ); ?>
  55. </time></a>
  56. <?php edit_comment_link( __( '(Edit)', '_ph' ), ' ' );
  57. ?>
  58. </div><!-- .comment-meta .commentmetadata -->
  59. </footer>
  60. <div class="comment-content"><?php comment_text(); ?></div>
  61. <div class="reply">
  62. <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
  63. </div><!-- .reply -->
  64. </article><!-- #comment-## -->
  65. <?php
  66. break;
  67. endswitch;
  68. }
  69. endif; // ends check for _ph_comment()
  70. if ( ! function_exists( '_ph_posted_on' ) ) :
  71. function _ph_posted_on() {
  72. printf( __( '<a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s" pubdate>%4$s</time></a><span class="byline"></span>', '_ph' ),
  73. esc_url( get_permalink() ),
  74. esc_attr( get_the_time() ),
  75. esc_attr( get_the_date( 'c' ) ),
  76. esc_html( get_the_date() ),
  77. esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
  78. esc_attr( sprintf( __( 'View all posts by %s', '_ph' ), get_the_author() ) ),
  79. esc_html( get_the_author() )
  80. );
  81. }
  82. endif;
  83. function _ph_categorized_blog() {
  84. if ( false === ( $all_the_cool_cats = get_transient( 'all_the_cool_cats' ) ) ) {
  85. // Create an array of all the categories that are attached to posts
  86. $all_the_cool_cats = get_categories( array(
  87. 'hide_empty' => 1,
  88. ) );
  89. // Count the number of categories that are attached to the posts
  90. $all_the_cool_cats = count( $all_the_cool_cats );
  91. set_transient( 'all_the_cool_cats', $all_the_cool_cats );
  92. }
  93. if ( '1' != $all_the_cool_cats ) {
  94. // This blog has more than 1 category so _ph_categorized_blog should return true
  95. return true;
  96. } else {
  97. // This blog has only 1 category so _ph_categorized_blog should return false
  98. return false;
  99. }
  100. }
  101. function _ph_category_transient_flusher() {
  102. // Like, beat it. Dig?
  103. delete_transient( 'all_the_cool_cats' );
  104. }
  105. add_action( 'edit_category', '_ph_category_transient_flusher' );
  106. add_action( 'save_post', '_ph_category_transient_flusher' );