PageRenderTime 51ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/template-tags.php

https://github.com/kcssm/news
PHP | 213 lines | 130 code | 32 blank | 51 comment | 22 complexity | 9d7fba0034a76991937033de9780d5c5 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 _gpp
  8. * @since _gpp 1.0
  9. */
  10. if ( ! function_exists( '_gpp_content_nav' ) ):
  11. /**
  12. * Display navigation to next/previous pages when applicable
  13. *
  14. * @since _gpp 1.0
  15. */
  16. function _gpp_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', '_gpp' ); ?></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', '_gpp' ) . '</span> %title' ); ?>
  26. <?php next_post_link( '<div class="nav-next">%link</div>', '%title <span class="meta-nav">' . _x( '&rarr;', 'Next post link', '_gpp' ) . '</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', '_gpp' ) ); ?></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>', '_gpp' ) ); ?></div>
  33. <?php endif; ?>
  34. <?php endif; ?>
  35. </nav><!-- #<?php echo $nav_id; ?> -->
  36. <?php
  37. }
  38. endif; // _gpp_content_nav
  39. if ( ! function_exists( '_gpp_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 _gpp 1.0
  46. */
  47. function _gpp_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:', '_gpp' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( '(Edit)', '_gpp' ), ' ' ); ?></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>', '_gpp' ), 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.', '_gpp' ); ?></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', '_gpp' ), get_comment_date(), get_comment_time() ); ?>
  75. </time></a>
  76. <?php edit_comment_link( __( '(Edit)', '_gpp' ), ' ' );
  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 _gpp_comment()
  90. if ( ! function_exists( '_gpp_posted_on' ) ) :
  91. /**
  92. * Prints HTML with meta information for the current post-date/time and author.
  93. *
  94. * @since _gpp 1.0
  95. */
  96. function _gpp_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>', '_gpp' ),
  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', '_gpp' ), 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 _gpp 1.0
  112. */
  113. function _gpp_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 _gpp_categorized_blog should return true
  125. return true;
  126. } else {
  127. // This blog has only 1 category so _gpp_categorized_blog should return false
  128. return false;
  129. }
  130. }
  131. /**
  132. * Flush out the transients used in _gpp_categorized_blog
  133. *
  134. * @since _gpp 1.0
  135. */
  136. function _gpp_category_transient_flusher() {
  137. // Like, beat it. Dig?
  138. delete_transient( 'all_the_cool_cats' );
  139. }
  140. add_action( 'edit_category', '_gpp_category_transient_flusher' );
  141. add_action( 'save_post', '_gpp_category_transient_flusher' );
  142. /**
  143. * Custom Post Thumbnail markup. Use jQuery to get data attributes on page for fancy presentations
  144. *
  145. * @since _gpp 1.0
  146. */
  147. function _gpp_post_thumbnail( $size = NULL ) {
  148. global $post;
  149. $thumb = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'thumbnail' );
  150. $large = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'large' );
  151. $title = get_the_title( get_post_thumbnail_id( $post->ID ) );
  152. echo '<img src="' . $thumb[0] . '" title="' . $title . '" data-image_large="' . $large[0] . '" data-image_thumb="' . $thumb[0] . '" class="wp-post-image" />';
  153. }
  154. /**
  155. * Count the number of footer widgets to enable dynamic classes for the footer
  156. *
  157. * @since _gpp 1.0
  158. */
  159. function _gpp_footer_widget_class() {
  160. $count = 0;
  161. if ( is_active_sidebar( 'footer-widget-1' ) )
  162. $count++;
  163. if ( is_active_sidebar( 'footer-widget-2' ) )
  164. $count++;
  165. if ( is_active_sidebar( 'footer-widget-3' ) )
  166. $count++;
  167. $class = '';
  168. switch ( $count ) {
  169. case '1':
  170. $class = 'one';
  171. break;
  172. case '2':
  173. $class = 'two';
  174. break;
  175. case '3':
  176. $class = 'three';
  177. break;
  178. }
  179. if ( $class )
  180. echo 'class="' . $class . '"';
  181. }