template-tags.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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() ) : ?>
  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. printf( __( '%1$s at %2$s', '_ph' ), get_comment_date(), get_comment_time() ); ?>
  54. </time></a>
  55. <?php edit_comment_link( __( '(Edit)', '_ph' ), ' ' );
  56. ?>
  57. </div>
  58. </footer>
  59. <div class="comment-content"><?php comment_text(); ?></div>
  60. <div class="reply">
  61. <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
  62. </div>
  63. </article>
  64. <?php
  65. break;
  66. endswitch;
  67. }
  68. endif;
  69. if ( ! function_exists( '_ph_posted_on' ) ) :
  70. function _ph_posted_on() {
  71. 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' ),
  72. esc_url( get_permalink() ),
  73. esc_attr( get_the_time() ),
  74. esc_attr( get_the_date( 'c' ) ),
  75. esc_html( get_the_date() ),
  76. esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
  77. esc_attr( sprintf( __( 'View all posts by %s', '_ph' ), get_the_author() ) ),
  78. esc_html( get_the_author() )
  79. );
  80. }
  81. endif;
  82. function _ph_categorized_blog() {
  83. if ( false === ( $all_the_cool_cats = get_transient( 'all_the_cool_cats' ) ) ) {
  84. // Create an array of all the categories that are attached to posts
  85. $all_the_cool_cats = get_categories( array(
  86. 'hide_empty' => 1,
  87. ) );
  88. // Count the number of categories that are attached to the posts
  89. $all_the_cool_cats = count( $all_the_cool_cats );
  90. set_transient( 'all_the_cool_cats', $all_the_cool_cats );
  91. }
  92. if ( '1' != $all_the_cool_cats ) {
  93. // This blog has more than 1 category so _ph_categorized_blog should return true
  94. return true;
  95. } else {
  96. // This blog has only 1 category so _ph_categorized_blog should return false
  97. return false;
  98. }
  99. }
  100. function _ph_category_transient_flusher() {
  101. // Like, beat it. Dig?
  102. delete_transient( 'all_the_cool_cats' );
  103. }
  104. add_action( 'edit_category', '_ph_category_transient_flusher' );
  105. add_action( 'save_post', '_ph_category_transient_flusher' );