PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/twentyfifteen/inc/template-tags.php

https://gitlab.com/ReneMC/Custom-wordpress-theme
PHP | 258 lines | 154 code | 30 blank | 74 comment | 39 complexity | 8fae5b710860233cfa195e0114c18f5a MD5 | raw file
  1. <?php
  2. /**
  3. * Custom template tags for Twenty Fifteen
  4. *
  5. * Eventually, some of the functionality here could be replaced by core features.
  6. *
  7. * @package WordPress
  8. * @subpackage Twenty_Fifteen
  9. * @since Twenty Fifteen 1.0
  10. */
  11. if ( ! function_exists( 'twentyfifteen_comment_nav' ) ) :
  12. /**
  13. * Display navigation to next/previous comments when applicable.
  14. *
  15. * @since Twenty Fifteen 1.0
  16. */
  17. function twentyfifteen_comment_nav() {
  18. // Are there comments to navigate through?
  19. if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) :
  20. ?>
  21. <nav class="navigation comment-navigation" role="navigation">
  22. <h2 class="screen-reader-text"><?php _e( 'Comment navigation', 'twentyfifteen' ); ?></h2>
  23. <div class="nav-links">
  24. <?php
  25. if ( $prev_link = get_previous_comments_link( __( 'Older Comments', 'twentyfifteen' ) ) ) :
  26. printf( '<div class="nav-previous">%s</div>', $prev_link );
  27. endif;
  28. if ( $next_link = get_next_comments_link( __( 'Newer Comments', 'twentyfifteen' ) ) ) :
  29. printf( '<div class="nav-next">%s</div>', $next_link );
  30. endif;
  31. ?>
  32. </div><!-- .nav-links -->
  33. </nav><!-- .comment-navigation -->
  34. <?php
  35. endif;
  36. }
  37. endif;
  38. if ( ! function_exists( 'twentyfifteen_entry_meta' ) ) :
  39. /**
  40. * Prints HTML with meta information for the categories, tags.
  41. *
  42. * @since Twenty Fifteen 1.0
  43. */
  44. function twentyfifteen_entry_meta() {
  45. if ( is_sticky() && is_home() && ! is_paged() ) {
  46. printf( '<span class="sticky-post">%s</span>', __( 'Featured', 'twentyfifteen' ) );
  47. }
  48. $format = get_post_format();
  49. if ( current_theme_supports( 'post-formats', $format ) ) {
  50. printf( '<span class="entry-format">%1$s<a href="%2$s">%3$s</a></span>',
  51. sprintf( '<span class="screen-reader-text">%s </span>', _x( 'Format', 'Used before post format.', 'twentyfifteen' ) ),
  52. esc_url( get_post_format_link( $format ) ),
  53. get_post_format_string( $format )
  54. );
  55. }
  56. if ( in_array( get_post_type(), array( 'post', 'attachment' ) ) ) {
  57. $time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
  58. if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
  59. $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
  60. }
  61. $time_string = sprintf( $time_string,
  62. esc_attr( get_the_date( 'c' ) ),
  63. get_the_date(),
  64. esc_attr( get_the_modified_date( 'c' ) ),
  65. get_the_modified_date()
  66. );
  67. printf( '<span class="posted-on"><span class="screen-reader-text">%1$s </span><a href="%2$s" rel="bookmark">%3$s</a></span>',
  68. _x( 'Posted on', 'Used before publish date.', 'twentyfifteen' ),
  69. esc_url( get_permalink() ),
  70. $time_string
  71. );
  72. }
  73. if ( 'post' == get_post_type() ) {
  74. if ( is_singular() || is_multi_author() ) {
  75. printf( '<span class="byline"><span class="author vcard"><span class="screen-reader-text">%1$s </span><a class="url fn n" href="%2$s">%3$s</a></span></span>',
  76. _x( 'Author', 'Used before post author name.', 'twentyfifteen' ),
  77. esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
  78. get_the_author()
  79. );
  80. }
  81. $categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'twentyfifteen' ) );
  82. if ( $categories_list && twentyfifteen_categorized_blog() ) {
  83. printf( '<span class="cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
  84. _x( 'Categories', 'Used before category names.', 'twentyfifteen' ),
  85. $categories_list
  86. );
  87. }
  88. $tags_list = get_the_tag_list( '', _x( ', ', 'Used between list items, there is a space after the comma.', 'twentyfifteen' ) );
  89. if ( $tags_list ) {
  90. printf( '<span class="tags-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
  91. _x( 'Tags', 'Used before tag names.', 'twentyfifteen' ),
  92. $tags_list
  93. );
  94. }
  95. }
  96. if ( is_attachment() && wp_attachment_is_image() ) {
  97. // Retrieve attachment metadata.
  98. $metadata = wp_get_attachment_metadata();
  99. printf( '<span class="full-size-link"><span class="screen-reader-text">%1$s </span><a href="%2$s">%3$s &times; %4$s</a></span>',
  100. _x( 'Full size', 'Used before full size attachment link.', 'twentyfifteen' ),
  101. esc_url( wp_get_attachment_url() ),
  102. $metadata['width'],
  103. $metadata['height']
  104. );
  105. }
  106. if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
  107. echo '<span class="comments-link">';
  108. /* translators: %s: post title */
  109. comments_popup_link( sprintf( __( 'Leave a comment<span class="screen-reader-text"> on %s</span>', 'twentyfifteen' ), get_the_title() ) );
  110. echo '</span>';
  111. }
  112. }
  113. endif;
  114. /**
  115. * Determine whether blog/site has more than one category.
  116. *
  117. * @since Twenty Fifteen 1.0
  118. *
  119. * @return bool True of there is more than one category, false otherwise.
  120. */
  121. function twentyfifteen_categorized_blog() {
  122. if ( false === ( $all_the_cool_cats = get_transient( 'twentyfifteen_categories' ) ) ) {
  123. // Create an array of all the categories that are attached to posts.
  124. $all_the_cool_cats = get_categories( array(
  125. 'fields' => 'ids',
  126. 'hide_empty' => 1,
  127. // We only need to know if there is more than one category.
  128. 'number' => 2,
  129. ) );
  130. // Count the number of categories that are attached to the posts.
  131. $all_the_cool_cats = count( $all_the_cool_cats );
  132. set_transient( 'twentyfifteen_categories', $all_the_cool_cats );
  133. }
  134. if ( $all_the_cool_cats > 1 ) {
  135. // This blog has more than 1 category so twentyfifteen_categorized_blog should return true.
  136. return true;
  137. } else {
  138. // This blog has only 1 category so twentyfifteen_categorized_blog should return false.
  139. return false;
  140. }
  141. }
  142. /**
  143. * Flush out the transients used in {@see twentyfifteen_categorized_blog()}.
  144. *
  145. * @since Twenty Fifteen 1.0
  146. */
  147. function twentyfifteen_category_transient_flusher() {
  148. // Like, beat it. Dig?
  149. delete_transient( 'twentyfifteen_categories' );
  150. }
  151. add_action( 'edit_category', 'twentyfifteen_category_transient_flusher' );
  152. add_action( 'save_post', 'twentyfifteen_category_transient_flusher' );
  153. if ( ! function_exists( 'twentyfifteen_post_thumbnail' ) ) :
  154. /**
  155. * Display an optional post thumbnail.
  156. *
  157. * Wraps the post thumbnail in an anchor element on index views, or a div
  158. * element when on single views.
  159. *
  160. * @since Twenty Fifteen 1.0
  161. */
  162. function twentyfifteen_post_thumbnail() {
  163. if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) {
  164. return;
  165. }
  166. if ( is_singular() ) :
  167. ?>
  168. <div class="post-thumbnail">
  169. <?php the_post_thumbnail(); ?>
  170. </div><!-- .post-thumbnail -->
  171. <?php else : ?>
  172. <a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true">
  173. <?php
  174. the_post_thumbnail( 'post-thumbnail', array( 'alt' => get_the_title() ) );
  175. ?>
  176. </a>
  177. <?php endif; // End is_singular()
  178. }
  179. endif;
  180. if ( ! function_exists( 'twentyfifteen_get_link_url' ) ) :
  181. /**
  182. * Return the post URL.
  183. *
  184. * Falls back to the post permalink if no URL is found in the post.
  185. *
  186. * @since Twenty Fifteen 1.0
  187. *
  188. * @see get_url_in_content()
  189. *
  190. * @return string The Link format URL.
  191. */
  192. function twentyfifteen_get_link_url() {
  193. $has_url = get_url_in_content( get_the_content() );
  194. return $has_url ? $has_url : apply_filters( 'the_permalink', get_permalink() );
  195. }
  196. endif;
  197. if ( ! function_exists( 'twentyfifteen_excerpt_more' ) && ! is_admin() ) :
  198. /**
  199. * Replaces "[...]" (appended to automatically generated excerpts) with ... and a 'Continue reading' link.
  200. *
  201. * @since Twenty Fifteen 1.0
  202. *
  203. * @return string 'Continue reading' link prepended with an ellipsis.
  204. */
  205. function twentyfifteen_excerpt_more( $more ) {
  206. $link = sprintf( '<a href="%1$s" class="more-link">%2$s</a>',
  207. esc_url( get_permalink( get_the_ID() ) ),
  208. /* translators: %s: Name of current post */
  209. sprintf( __( 'Continue reading %s', 'twentyfifteen' ), '<span class="screen-reader-text">' . get_the_title( get_the_ID() ) . '</span>' )
  210. );
  211. return ' &hellip; ' . $link;
  212. }
  213. add_filter( 'excerpt_more', 'twentyfifteen_excerpt_more' );
  214. endif;
  215. if ( ! function_exists( 'twentyfifteen_the_custom_logo' ) ) :
  216. /**
  217. * Displays the optional custom logo.
  218. *
  219. * Does nothing if the custom logo is not available.
  220. *
  221. * @since Twenty Fifteen 1.5
  222. */
  223. function twentyfifteen_the_custom_logo() {
  224. if ( function_exists( 'the_custom_logo' ) ) {
  225. the_custom_logo();
  226. }
  227. }
  228. endif;