/includes/functions-template-tags.php

  1. <?php 
  2. /** 
  3. * Template Tags 
  4. * 
  5. * Custom template tags e.g. Post nav, Posted on 
  6. * 
  7. * @package Responsive_II 
  8. * @license license.txt 
  9. * @copyright 2014 CyberChimps Inc 
  10. * @since 0.0.1 
  11. * 
  12. * Please do not edit this file. This file is part of the Responsive_II Framework and all modifications 
  13. * should be made in a child theme. 
  14. */ 
  15.  
  16. // If this file is called directly, abort. 
  17. if ( ! defined( 'WPINC' ) ) { 
  18. die; 
  19.  
  20. if ( !function_exists( 'responsive_II_paging_nav' ) ) { 
  21. /** 
  22. * Display navigation to next/previous set of posts when applicable. 
  23. * 
  24. * @return void 
  25. */ 
  26. function responsive_II_paging_nav() { 
  27. // Don't print empty markup if there's only one page. 
  28. if ( $GLOBALS['wp_query']->max_num_pages < 2 ) { 
  29. return; 
  30. ?> 
  31. <nav class="navigation paging-navigation" role="navigation"> 
  32. <h1 class="screen-reader-text"><?php _e( 'Posts navigation', 'responsive-II' ); ?></h1> 
  33.  
  34. <div class="nav-links"> 
  35.  
  36. <?php if ( get_next_posts_link() ) : ?> 
  37. <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'responsive-II' ) ); ?></div> 
  38. <?php endif; ?> 
  39.  
  40. <?php if ( get_previous_posts_link() ) : ?> 
  41. <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'responsive-II' ) ); ?></div> 
  42. <?php endif; ?> 
  43.  
  44. </div> 
  45. <!-- .nav-links --> 
  46. </nav><!-- .navigation --> 
  47. <?php 
  48.  
  49. if ( !function_exists( 'responsive_II_post_nav' ) ) { 
  50. /** 
  51. * Display navigation to next/previous post when applicable. 
  52. * 
  53. * @return void 
  54. */ 
  55. function responsive_II_post_nav() { 
  56. // Don't print empty markup if there's nowhere to navigate. 
  57. $previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true ); 
  58. $next = get_adjacent_post( false, '', false ); 
  59.  
  60. if ( !$next && !$previous ) { 
  61. return; 
  62. ?> 
  63. <nav class="navigation post-navigation" role="navigation"> 
  64. <h1 class="screen-reader-text"><?php _e( 'Post navigation', 'responsive-II' ); ?></h1> 
  65.  
  66. <div class="nav-links"> 
  67.  
  68. <div class="nav-previous"><?php previous_post_link( '%link', _x( '<span class="meta-nav">←</span> %title', 'Previous post link', 'responsive-II' ) ); ?></div> 
  69. <div class="nav-next"><?php next_post_link( '%link', _x( '%title <span class="meta-nav">→</span>', 'Next post link', 'responsive-II' ) ); ?></div> 
  70.  
  71. </div> 
  72. <!-- .nav-links --> 
  73. </nav><!-- .navigation --> 
  74. <?php 
  75.  
  76. if ( !function_exists( 'responsive_II_post_thumbnail' ) ) { 
  77. /** 
  78. * Creates the post thumbnail used throughout the templates 
  79. * 
  80. * @param string $size 
  81. * @param null $attr 
  82. */ 
  83. function responsive_II_post_thumbnail( $size = 'post-thumbnail', $attr = null ) { 
  84. $size = apply_filters( 'responsive_II_filter_the_post_thumbnail_size', $size ); 
  85. $attr = apply_filters( 'responsive_II_filter_the_post_thumbnail_attr', $attr ); 
  86. ?> 
  87. <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"> 
  88. <?php the_post_thumbnail( $size, $attr ); ?> 
  89. </a> 
  90. <?php 
  91.  
  92. if ( !function_exists( 'responsive_II_comment' ) ) { 
  93. /** 
  94. * Template for comments and pingbacks. 
  95. * 
  96. * Used as a callback by wp_list_comments() for displaying the comments. 
  97. */ 
  98. function responsive_II_comment( $comment, $args, $depth ) { 
  99. $GLOBALS['comment'] = $comment; 
  100.  
  101. if ( 'pingback' == $comment->comment_type || 'trackback' == $comment->comment_type ) : ?> 
  102.  
  103. <li id="comment-<?php comment_ID(); ?>" <?php comment_class(); ?>> 
  104. <div class="comment-body"> 
  105. <?php _e( 'Pingback:', 'responsive-II' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( 'Edit', 'responsive-II' ), '<span class="edit-link">', '</span>' ); ?> 
  106. </div> 
  107.  
  108. <?php else : ?> 
  109.  
  110. <li id="comment-<?php comment_ID(); ?>" <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ); ?>> 
  111. <article id="div-comment-<?php comment_ID(); ?>" class="comment-body"> 
  112. <footer class="comment-meta"> 
  113. <div class="comment-author vcard"> 
  114. <?php if ( 0 != $args['avatar_size'] ) { 
  115. echo get_avatar( $comment, $args['avatar_size'] ); 
  116. } ?> 
  117. <?php printf( __( '%s <span class="says">says:</span>', 'responsive-II' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?> 
  118. </div> 
  119. <!-- .comment-author --> 
  120.  
  121. <div class="comment-metadata"> 
  122. <a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>"> 
  123. <time datetime="<?php comment_time( 'c' ); ?>"> 
  124. <?php printf( _x( '%1$s at %2$s', '1: date, 2: time', 'responsive-II' ), get_comment_date(), get_comment_time() ); ?> 
  125. </time> 
  126. </a> 
  127. <?php edit_comment_link( __( 'Edit', 'responsive-II' ), '<span class="edit-link">', '</span>' ); ?> 
  128. </div> 
  129. <!-- .comment-metadata --> 
  130.  
  131. <?php if ( '0' == $comment->comment_approved ) : ?> 
  132. <p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'responsive-II' ); ?></p> 
  133. <?php endif; ?> 
  134. </footer> 
  135. <!-- .comment-meta --> 
  136.  
  137. <div class="comment-content"> 
  138. <?php comment_text(); ?> 
  139. </div> 
  140. <!-- .comment-content --> 
  141.  
  142. <?php 
  143. comment_reply_link( array_merge( $args, array( 
  144. 'add_below' => 'div-comment',  
  145. 'depth' => $depth,  
  146. 'max_depth' => $args['max_depth'],  
  147. 'before' => '<div class="reply">',  
  148. 'after' => '</div>',  
  149. ) ) ); 
  150. ?> 
  151. </article> 
  152. <!-- .comment-body --> 
  153.  
  154. <?php 
  155. endif; 
  156.  
  157. /** 
  158. * This function prints post meta data. 
  159. * 
  160. * Ulrich Pogson Contribution 
  161. * 
  162. */ 
  163. if ( !function_exists( 'responsive_II_post_meta_data' ) ) { 
  164.  
  165. function responsive_II_post_meta_data() { 
  166.  
  167. // Apply filter to get by_line_date option working. 
  168. $by_line_date = apply_filters( 'responsive_II_by_line_date', '1' ); 
  169. if( $by_line_date ) { 
  170. printf( 
  171. /** Translators: (Posted on )(Date) */ 
  172. __( '%1$s %2$s', 'responsive-II' ),  
  173. '<span class="meta-prep meta-prep-author posted">' . __( 'Posted on', 'responsive-II' ) . ' </span>',  
  174. sprintf( 
  175. '<a href="%1$s" title="%2$s" rel="bookmark"><time class="timestamp updated" itemprop="datePublished" datetime="%3$s">%4$s</time></a>',  
  176. esc_url( get_permalink() ),  
  177. esc_attr( get_the_time() ),  
  178. esc_html( get_the_date('c')),  
  179. esc_html( get_the_date() ) 
  180. ); 
  181.  
  182. // Apply filter to get by_line_author option working. 
  183. $by_line_author = apply_filters( 'responsive_II_by_line_author', '1' ); 
  184. if( $by_line_author ) { 
  185. printf( 
  186. /** Translators: ( by )(Author) */ 
  187. __( '%1$s %2$s', 'responsive-II' ),  
  188. '<span class="byline"> ' . __( 'by', 'responsive-II' ) . ' </span>',  
  189. sprintf( 
  190. '<span class="author vcard" itemprop="author" itemscope="itemscope" itemtype="http://schema.org/Person"><a class="url fn n" href="%1$s" title="%2$s" itemprop="url" rel="author"><span itemprop="name">%3$s</span></a></span>',  
  191. get_author_posts_url( get_the_author_meta( 'ID' ) ),  
  192. sprintf( esc_attr__( 'View all posts by %s', 'responsive-II' ), get_the_author() ),  
  193. esc_attr( get_the_author() ) 
  194. ); 
  195.  
  196. if ( !function_exists( 'responsive_II_posted_on' ) ) { 
  197. /** 
  198. * Prints HTML with meta information for the current post-date/time and author. 
  199. */ 
  200. function responsive_II_posted_on() { 
  201. $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>'; 
  202. if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) { 
  203. $time_string .= '<time class="updated" datetime="%3$s">%4$s</time>'; 
  204.  
  205. $time_string = sprintf( $time_string,  
  206. esc_attr( get_the_date( 'c' ) ),  
  207. esc_html( get_the_date() ),  
  208. esc_attr( get_the_modified_date( 'c' ) ),  
  209. esc_html( get_the_modified_date() ) 
  210. ); 
  211.  
  212. printf( __( '<span class="posted-on">Posted on %1$s</span><span class="byline"> by %2$s</span>', 'responsive-II' ),  
  213. sprintf( '<a href="%1$s" rel="bookmark">%2$s</a>',  
  214. esc_url( get_permalink() ),  
  215. $time_string 
  216. ),  
  217. sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s">%2$s</a></span>',  
  218. esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),  
  219. esc_html( get_the_author() ) 
  220. ); 
  221.  
  222. /** 
  223. * Returns true if a blog has more than 1 category. 
  224. */ 
  225. function responsive_II_categorized_blog() { 
  226. if ( false === ( $all_the_cool_cats = get_transient( 'all_the_cool_cats' ) ) ) { 
  227. // Create an array of all the categories that are attached to posts. 
  228. $all_the_cool_cats = get_categories( array( 'hide_empty' => 1 ) ); 
  229.  
  230. // Count the number of categories that are attached to the posts. 
  231. $all_the_cool_cats = count( $all_the_cool_cats ); 
  232.  
  233. set_transient( 'all_the_cool_cats', $all_the_cool_cats ); 
  234.  
  235. if ( '1' != $all_the_cool_cats ) { 
  236. // This blog has more than 1 category so responsive_II_categorized_blog should return true. 
  237. return true; 
  238. } else { 
  239. // This blog has only 1 category so responsive_II_categorized_blog should return false. 
  240. return false; 
  241.  
  242. /** 
  243. * Flush out the transients used in responsive_II_categorized_blog. 
  244. */ 
  245. function responsive_II_category_transient_flusher() { 
  246. // Like, beat it. Dig? 
  247. delete_transient( 'all_the_cool_cats' ); 
  248.  
  249. add_action( 'edit_category', 'responsive_II_category_transient_flusher' ); 
  250. add_action( 'save_post', 'responsive_II_category_transient_flusher' ); 
  251.  
  252. if ( !function_exists( 'responsive_II_archive_title' ) ) { 
  253. /** 
  254. * Prints respective title for the archive page. 
  255. */ 
  256. function responsive_II_archive_title( $display = true ) { 
  257. if ( is_category() ) { 
  258. $archive_title = single_cat_title( "", false ); 
  259.  
  260. } elseif ( is_tag() ) { 
  261. $archive_title = single_tag_title( "", false ); 
  262.  
  263. } elseif ( is_author() ) { 
  264. $archive_title = sprintf( __( 'Author: %s', 'responsive-II' ), '<span class="vcard">' . get_the_author() . '</span>' ); 
  265.  
  266. } elseif ( is_day() ) { 
  267. $archive_title = sprintf( __( 'Daily Archives: %s', 'responsive-II' ), '<span>' . get_the_date() . '</span>' ); 
  268.  
  269. } elseif ( is_month() ) { 
  270. $archive_title = sprintf( __( 'Monthly Archives: %s', 'responsive-II' ), '<span>' . get_the_date( _x( 'F Y', 'monthly archives date format', 'responsive-II' ) ) . '</span>' ); 
  271.  
  272. } elseif ( is_year() ) { 
  273. $archive_title = sprintf( __( 'Yearly Archives: %s', 'responsive-II' ), '<span>' . get_the_date( _x( 'Y', 'yearly archives date format', 'responsive-II' ) ) . '</span>' ); 
  274.  
  275. } elseif ( is_tax( 'post_format', 'post-format-aside' ) ) { 
  276. $archive_title = __( 'Asides', 'responsive-II' ); 
  277.  
  278. } elseif ( is_tax( 'post_format', 'post-format-gallery' ) ) { 
  279. $archive_title = __( 'Galleries', 'responsive-II' ); 
  280.  
  281. } elseif ( is_tax( 'post_format', 'post-format-image' ) ) { 
  282. $archive_title = __( 'Images', 'responsive-II' ); 
  283.  
  284. } elseif ( is_tax( 'post_format', 'post-format-video' ) ) { 
  285. $archive_title = __( 'Videos', 'responsive-II' ); 
  286.  
  287. } elseif ( is_tax( 'post_format', 'post-format-quote' ) ) { 
  288. $archive_title = __( 'Quotes', 'responsive-II' ); 
  289.  
  290. } elseif ( is_tax( 'post_format', 'post-format-link' ) ) { 
  291. $archive_title = __( 'Links', 'responsive-II' ); 
  292.  
  293. } elseif ( is_tax( 'post_format', 'post-format-status' ) ) { 
  294. $archive_title = __( 'Statuses', 'responsive-II' ); 
  295.  
  296. } elseif ( is_tax( 'post_format', 'post-format-audio' ) ) { 
  297. $archive_title = __( 'Audios', 'responsive-II' ); 
  298.  
  299. } elseif ( is_tax( 'post_format', 'post-format-chat' ) ) { 
  300. $archive_title = __( 'Chats', 'responsive-II' ); 
  301.  
  302. } else { 
  303. $archive_title = __( 'Archives', 'responsive-II' ); 
  304.  
  305.  
  306. if ( $display ) { 
  307. echo $archive_title; 
  308. } else { 
  309. return $archive_title; 
  310.  
  311.  
  312. /** 
  313. * Mobile menu title 
  314. */ 
  315. function responsive_II_menu_title( $display = true ) { 
  316.  
  317. $page_title = __( 'Menu', 'responsive-II' ); 
  318.  
  319. $page_title = apply_filters( 'responsive_II_menu_title', $page_title ); 
  320.  
  321. if ( $display ) { 
  322. echo $page_title; 
  323. } else { 
  324. return $page_title; 
  325.  
.