template-tags.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 UIU_CSE
  8. */
  9. if ( ! function_exists( 'uiu_cse_posted_on' ) ) :
  10. /**
  11. * Prints HTML with meta information for the current post-date/time.
  12. */
  13. function uiu_cse_posted_on() {
  14. $time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
  15. if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
  16. $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
  17. }
  18. $time_string = sprintf(
  19. $time_string,
  20. esc_attr( get_the_date( DATE_W3C ) ),
  21. esc_html( get_the_date() ),
  22. esc_attr( get_the_modified_date( DATE_W3C ) ),
  23. esc_html( get_the_modified_date() )
  24. );
  25. $posted_on = sprintf(
  26. /* translators: %s: post date. */
  27. esc_html_x( 'Posted on %s', 'post date', 'uiu-cse' ),
  28. '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
  29. );
  30. echo '<span class="posted-on">' . $posted_on . '</span>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
  31. }
  32. endif;
  33. if ( ! function_exists( 'uiu_cse_posted_by' ) ) :
  34. /**
  35. * Prints HTML with meta information for the current author.
  36. */
  37. function uiu_cse_posted_by() {
  38. $byline = sprintf(
  39. /* translators: %s: post author. */
  40. esc_html_x( 'by %s', 'post author', 'uiu-cse' ),
  41. '<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>'
  42. );
  43. echo '<span class="byline"> ' . $byline . '</span>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
  44. }
  45. endif;
  46. if ( ! function_exists( 'uiu_cse_entry_footer' ) ) :
  47. /**
  48. * Prints HTML with meta information for the categories, tags and comments.
  49. */
  50. function uiu_cse_entry_footer() {
  51. // Hide category and tag text for pages.
  52. if ( 'post' === get_post_type() ) {
  53. /* translators: used between list items, there is a space after the comma */
  54. $categories_list = get_the_category_list( esc_html__( ', ', 'uiu-cse' ) );
  55. if ( $categories_list ) {
  56. /* translators: 1: list of categories. */
  57. printf( '<span class="cat-links">' . esc_html__( 'Posted in %1$s', 'uiu-cse' ) . '</span>', $categories_list ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
  58. }
  59. /* translators: used between list items, there is a space after the comma */
  60. $tags_list = get_the_tag_list( '', esc_html_x( ', ', 'list item separator', 'uiu-cse' ) );
  61. if ( $tags_list ) {
  62. /* translators: 1: list of tags. */
  63. printf( '<span class="tags-links">' . esc_html__( 'Tagged %1$s', 'uiu-cse' ) . '</span>', $tags_list ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
  64. }
  65. }
  66. if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
  67. echo '<span class="comments-link">';
  68. comments_popup_link(
  69. sprintf(
  70. wp_kses(
  71. /* translators: %s: post title */
  72. __( 'Leave a Comment<span class="screen-reader-text"> on %s</span>', 'uiu-cse' ),
  73. array(
  74. 'span' => array(
  75. 'class' => array(),
  76. ),
  77. )
  78. ),
  79. wp_kses_post( get_the_title() )
  80. )
  81. );
  82. echo '</span>';
  83. }
  84. edit_post_link(
  85. sprintf(
  86. wp_kses(
  87. /* translators: %s: Name of current post. Only visible to screen readers */
  88. __( 'Edit <span class="screen-reader-text">%s</span>', 'uiu-cse' ),
  89. array(
  90. 'span' => array(
  91. 'class' => array(),
  92. ),
  93. )
  94. ),
  95. wp_kses_post( get_the_title() )
  96. ),
  97. '<span class="edit-link">',
  98. '</span>'
  99. );
  100. }
  101. endif;
  102. if ( ! function_exists( 'uiu_cse_post_thumbnail' ) ) :
  103. /**
  104. * Displays an optional post thumbnail.
  105. *
  106. * Wraps the post thumbnail in an anchor element on index views, or a div
  107. * element when on single views.
  108. */
  109. function uiu_cse_post_thumbnail() {
  110. if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) {
  111. return;
  112. }
  113. if ( is_singular() ) :
  114. ?>
  115. <div class="post-thumbnail">
  116. <?php the_post_thumbnail(); ?>
  117. </div><!-- .post-thumbnail -->
  118. <?php else : ?>
  119. <a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true" tabindex="-1">
  120. <?php
  121. the_post_thumbnail(
  122. 'post-thumbnail',
  123. array(
  124. 'alt' => the_title_attribute(
  125. array(
  126. 'echo' => false,
  127. )
  128. ),
  129. )
  130. );
  131. ?>
  132. </a>
  133. <?php
  134. endif; // End is_singular().
  135. }
  136. endif;
  137. if ( ! function_exists( 'wp_body_open' ) ) :
  138. /**
  139. * Shim for sites older than 5.2.
  140. *
  141. * @link https://core.trac.wordpress.org/ticket/12563
  142. */
  143. function wp_body_open() {
  144. do_action( 'wp_body_open' );
  145. }
  146. endif;