PageRenderTime 54ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/themes/panoramic/library/includes/template-tags.php

https://gitlab.com/oresticouci/ablSportsConsulting
PHP | 232 lines | 154 code | 35 blank | 43 comment | 34 complexity | e20607a53d54d8c05d81eefc3bca496b MD5 | raw file
  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 panoramic
  8. */
  9. if ( ! function_exists( 'panoramic_paging_nav' ) ) :
  10. /**
  11. * Display navigation to next/previous set of posts when applicable.
  12. */
  13. function panoramic_paging_nav() {
  14. // Don't print empty markup if there's only one page.
  15. if ( $GLOBALS['wp_query']->max_num_pages < 2 ) {
  16. return;
  17. }
  18. ?>
  19. <nav class="navigation paging-navigation" role="navigation">
  20. <h1 class="screen-reader-text"><?php _e( 'Posts navigation', 'panoramic' ); ?></h1>
  21. <div class="nav-links">
  22. <?php if ( get_next_posts_link() ) : ?>
  23. <div class="nav-previous"><?php next_posts_link( __( 'Older posts <span class="meta-nav">&rarr;</span>', 'panoramic' ) ); ?></div>
  24. <?php endif; ?>
  25. <?php if ( get_previous_posts_link() ) : ?>
  26. <div class="nav-next"><?php previous_posts_link( __( '<span class="meta-nav">&larr;</span> Newer posts', 'panoramic' ) ); ?></div>
  27. <?php endif; ?>
  28. </div><!-- .nav-links -->
  29. </nav><!-- .navigation -->
  30. <?php
  31. }
  32. endif;
  33. if ( ! function_exists( 'panoramic_post_nav' ) ) :
  34. /**
  35. * Display navigation to next/previous post when applicable.
  36. */
  37. function panoramic_post_nav() {
  38. // Don't print empty markup if there's nowhere to navigate.
  39. $previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
  40. $next = get_adjacent_post( false, '', false );
  41. if ( ! $next && ! $previous ) {
  42. return;
  43. }
  44. ?>
  45. <nav class="navigation post-navigation" role="navigation">
  46. <h1 class="screen-reader-text"><?php _e( 'Post navigation', 'panoramic' ); ?></h1>
  47. <div class="nav-links">
  48. <?php
  49. $slider_categories = get_theme_mod( 'panoramic-slider-categories', '' );
  50. previous_post_link( '<div class="nav-previous">%link</div>', _x( '%title&nbsp;<span class="meta-nav">&rarr;</span>', 'Previous post link', 'panoramic' ), false, $slider_categories);
  51. next_post_link( '<div class="nav-next">%link</div>', _x( '<span class="meta-nav">&larr;</span>&nbsp;%title', 'Next post link', 'panoramic' ), false, $slider_categories);
  52. ?>
  53. </div><!-- .nav-links -->
  54. </nav><!-- .navigation -->
  55. <?php
  56. }
  57. endif;
  58. if ( ! function_exists( 'panoramic_posted_on' ) ) :
  59. /**
  60. * Prints HTML with meta information for the current post-date/time and author.
  61. */
  62. function panoramic_posted_on() {
  63. $time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
  64. if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
  65. $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
  66. }
  67. $time_string = sprintf( $time_string,
  68. esc_attr( get_the_date( 'c' ) ),
  69. esc_html( get_the_date() ),
  70. esc_attr( get_the_modified_date( 'c' ) ),
  71. esc_html( get_the_modified_date() )
  72. );
  73. $posted_on = sprintf(
  74. _x( 'Posted on %s', 'post date', 'panoramic' ),
  75. '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
  76. );
  77. $byline = sprintf(
  78. _x( 'by %s', 'post author', 'panoramic' ),
  79. '<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>'
  80. );
  81. echo '<span class="posted-on">' . $posted_on . '</span><span class="byline"> ' . $byline . '</span>';
  82. }
  83. endif;
  84. if ( ! function_exists( 'panoramic_entry_footer' ) ) :
  85. /**
  86. * Prints HTML with meta information for the categories, tags and comments.
  87. */
  88. function panoramic_entry_footer() {
  89. // Hide category and tag text for pages.
  90. if ( 'post' == get_post_type() ) {
  91. /* translators: used between list items, there is a space after the comma */
  92. $categories_list = get_the_category_list( __( ', ', 'panoramic' ) );
  93. if ( $categories_list && panoramic_categorized_blog() ) {
  94. printf( '<span class="cat-links">' . __( 'Posted in %1$s ', 'panoramic' ) . '</span>', $categories_list );
  95. }
  96. /* translators: used between list items, there is a space after the comma */
  97. $tags_list = get_the_tag_list( '', __( ', ', 'panoramic' ) );
  98. if ( $tags_list ) {
  99. printf( '<span class="tags-links">' . __( 'Tagged %1$s ', 'panoramic' ) . '</span>', $tags_list );
  100. }
  101. }
  102. if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
  103. echo '<span class="comments-link">';
  104. comments_popup_link( __( 'Leave a comment ', 'panoramic' ), __( '1 Comment ', 'panoramic' ), __( '% Comments ', 'panoramic' ) );
  105. echo '</span>';
  106. }
  107. edit_post_link( __( 'Edit', 'panoramic' ), '<span class="edit-link">', '</span>' );
  108. }
  109. endif;
  110. /**
  111. * Returns true if a blog has more than 1 category.
  112. *
  113. * @return bool
  114. */
  115. function panoramic_categorized_blog() {
  116. if ( false === ( $all_the_cool_cats = get_transient( 'panoramic_categories' ) ) ) {
  117. // Create an array of all the categories that are attached to posts.
  118. $all_the_cool_cats = get_categories( array(
  119. 'fields' => 'ids',
  120. 'hide_empty' => 1,
  121. // We only need to know if there is more than one category.
  122. 'number' => 2,
  123. ) );
  124. // Count the number of categories that are attached to the posts.
  125. $all_the_cool_cats = count( $all_the_cool_cats );
  126. set_transient( 'panoramic_categories', $all_the_cool_cats );
  127. }
  128. if ( $all_the_cool_cats > 1 ) {
  129. // This blog has more than 1 category so panoramic_categorized_blog should return true.
  130. return true;
  131. } else {
  132. // This blog has only 1 category so panoramic_categorized_blog should return false.
  133. return false;
  134. }
  135. }
  136. if ( ! function_exists( 'panoramic_comment' ) ) :
  137. /**
  138. * Template for comments and pingbacks.
  139. *
  140. * Used as a callback by wp_list_comments() for displaying the comments.
  141. */
  142. function panoramic_comment( $comment, $args, $depth ) {
  143. $GLOBALS['comment'] = $comment;
  144. if ( 'pingback' == $comment->comment_type || 'trackback' == $comment->comment_type ) : ?>
  145. <li id="comment-<?php comment_ID(); ?>" <?php comment_class(); ?>>
  146. <div class="comment-body">
  147. <?php _e( 'Pingback:', 'panoramic' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( 'Edit', 'panoramic' ), '<span class="edit-link">', '</span>' ); ?>
  148. </div>
  149. <?php else : ?>
  150. <li id="comment-<?php comment_ID(); ?>" <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ); ?>>
  151. <article id="div-comment-<?php comment_ID(); ?>" class="comment-body">
  152. <footer class="comment-meta">
  153. <div class="comment-author vcard">
  154. <?php if ( 0 != $args['avatar_size'] ) { echo get_avatar( $comment, $args['avatar_size'] ); } ?>
  155. <?php printf( __( '%s <span class="says">says:</span>', 'panoramic' ), sprintf( '<span class="fn">%s</span>', get_comment_author_link() ) ); ?>
  156. </div><!-- .comment-author -->
  157. <?php if ( '0' == $comment->comment_approved ) : ?>
  158. <p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'panoramic' ); ?></p>
  159. <?php endif; ?>
  160. </footer><!-- .comment-meta -->
  161. <div class="comment-content">
  162. <?php comment_text(); ?>
  163. </div><!-- .comment-content -->
  164. <div class="comment-metadata">
  165. <a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
  166. <time datetime="<?php comment_time( 'c' ); ?>">
  167. <?php printf( _x( '%1$s at %2$s', '1: date, 2: time', 'panoramic' ), get_comment_date(), get_comment_time() ); ?>
  168. </time>
  169. </a>
  170. <?php edit_comment_link( __( 'Edit', 'panoramic' ), '<span class="edit-link">', '</span>' ); ?>
  171. </div><!-- .comment-metadata -->
  172. <?php
  173. comment_reply_link( array_merge( $args, array(
  174. 'add_below' => 'div-comment',
  175. 'depth' => $depth,
  176. 'max_depth' => $args['max_depth'],
  177. 'before' => '<div class="reply">',
  178. 'after' => '</div>',
  179. ) ) );
  180. ?>
  181. </article><!-- .comment-body -->
  182. <?php
  183. endif;
  184. }
  185. endif; // ends check for panoramic_comment()
  186. /**
  187. * Flush out the transients used in panoramic_categorized_blog.
  188. */
  189. function panoramic_category_transient_flusher() {
  190. if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
  191. return;
  192. }
  193. // Like, beat it. Dig?
  194. delete_transient( 'panoramic_categories' );
  195. }
  196. add_action( 'edit_category', 'panoramic_category_transient_flusher' );
  197. add_action( 'save_post', 'panoramic_category_transient_flusher' );