[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-content/themes/twentynineteen/inc/ -> template-tags.php (source)

   1  <?php
   2  /**
   3   * Custom template tags for this theme
   4   *
   5   * @package WordPress
   6   * @subpackage Twenty_Nineteen
   7   * @since Twenty Nineteen 1.0
   8   */
   9  
  10  if ( ! function_exists( 'twentynineteen_posted_on' ) ) :
  11      /**
  12       * Prints HTML with meta information for the current post-date/time.
  13       */
  14  	function twentynineteen_posted_on() {
  15          $time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
  16          if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
  17              $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
  18          }
  19  
  20          $time_string = sprintf(
  21              $time_string,
  22              esc_attr( get_the_date( DATE_W3C ) ),
  23              esc_html( get_the_date() ),
  24              esc_attr( get_the_modified_date( DATE_W3C ) ),
  25              esc_html( get_the_modified_date() )
  26          );
  27  
  28          printf(
  29              '<span class="posted-on">%1$s<a href="%2$s" rel="bookmark">%3$s</a></span>',
  30              twentynineteen_get_icon_svg( 'watch', 16 ),
  31              esc_url( get_permalink() ),
  32              $time_string
  33          );
  34      }
  35  endif;
  36  
  37  if ( ! function_exists( 'twentynineteen_posted_by' ) ) :
  38      /**
  39       * Prints HTML with meta information about theme author.
  40       */
  41  	function twentynineteen_posted_by() {
  42          printf(
  43              /* translators: 1: SVG icon. 2: Post author, only visible to screen readers. 3: Author link. */
  44              '<span class="byline">%1$s<span class="screen-reader-text">%2$s</span><span class="author vcard"><a class="url fn n" href="%3$s">%4$s</a></span></span>',
  45              twentynineteen_get_icon_svg( 'person', 16 ),
  46              /* translators: Hidden accessibility text. */
  47              __( 'Posted by', 'twentynineteen' ),
  48              esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
  49              esc_html( get_the_author() )
  50          );
  51      }
  52  endif;
  53  
  54  if ( ! function_exists( 'twentynineteen_comment_count' ) ) :
  55      /**
  56       * Prints HTML with the comment count for the current post.
  57       */
  58  	function twentynineteen_comment_count() {
  59          if ( ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
  60              echo '<span class="comments-link">';
  61              echo twentynineteen_get_icon_svg( 'comment', 16 );
  62  
  63              /* translators: %s: Post title. Only visible to screen readers. */
  64              comments_popup_link( sprintf( __( 'Leave a comment<span class="screen-reader-text"> on %s</span>', 'twentynineteen' ), get_the_title() ) );
  65  
  66              echo '</span>';
  67          }
  68      }
  69  endif;
  70  
  71  if ( ! function_exists( 'twentynineteen_entry_footer' ) ) :
  72      /**
  73       * Prints HTML with meta information for the categories, tags and comments.
  74       */
  75  	function twentynineteen_entry_footer() {
  76  
  77          // Hide author, post date, category and tag text for pages.
  78          if ( 'post' === get_post_type() ) {
  79  
  80              // Posted by.
  81              twentynineteen_posted_by();
  82  
  83              // Posted on.
  84              twentynineteen_posted_on();
  85  
  86              $categories_list = get_the_category_list( wp_get_list_item_separator() );
  87              if ( $categories_list ) {
  88                  printf(
  89                      /* translators: 1: SVG icon. 2: Posted in label, only visible to screen readers. 3: List of categories. */
  90                      '<span class="cat-links">%1$s<span class="screen-reader-text">%2$s</span>%3$s</span>',
  91                      twentynineteen_get_icon_svg( 'archive', 16 ),
  92                      /* translators: Hidden accessibility text. */
  93                      __( 'Posted in', 'twentynineteen' ),
  94                      $categories_list
  95                  ); // WPCS: XSS OK.
  96              }
  97  
  98              $tags_list = get_the_tag_list( '', wp_get_list_item_separator() );
  99              if ( $tags_list && ! is_wp_error( $tags_list ) ) {
 100                  printf(
 101                      /* translators: 1: SVG icon. 2: Posted in label, only visible to screen readers. 3: List of tags. */
 102                      '<span class="tags-links">%1$s<span class="screen-reader-text">%2$s </span>%3$s</span>',
 103                      twentynineteen_get_icon_svg( 'tag', 16 ),
 104                      /* translators: Hidden accessibility text. */
 105                      __( 'Tags:', 'twentynineteen' ),
 106                      $tags_list
 107                  ); // WPCS: XSS OK.
 108              }
 109          }
 110  
 111          // Comment count.
 112          if ( ! is_singular() ) {
 113              twentynineteen_comment_count();
 114          }
 115  
 116          // Edit post link.
 117          edit_post_link(
 118              sprintf(
 119                  wp_kses(
 120                      /* translators: %s: Post title. Only visible to screen readers. */
 121                      __( 'Edit <span class="screen-reader-text">%s</span>', 'twentynineteen' ),
 122                      array(
 123                          'span' => array(
 124                              'class' => array(),
 125                          ),
 126                      )
 127                  ),
 128                  get_the_title()
 129              ),
 130              '<span class="edit-link">' . twentynineteen_get_icon_svg( 'edit', 16 ),
 131              '</span>'
 132          );
 133      }
 134  endif;
 135  
 136  if ( ! function_exists( 'twentynineteen_post_thumbnail' ) ) :
 137      /**
 138       * Displays an optional post thumbnail.
 139       *
 140       * Wraps the post thumbnail in an anchor element on index views, or a div
 141       * element when on single views.
 142       */
 143  	function twentynineteen_post_thumbnail() {
 144          if ( ! twentynineteen_can_show_post_thumbnail() ) {
 145              return;
 146          }
 147  
 148          if ( is_singular() ) :
 149              ?>
 150  
 151              <figure class="post-thumbnail">
 152                  <?php the_post_thumbnail(); ?>
 153              </figure><!-- .post-thumbnail -->
 154  
 155              <?php
 156          else :
 157              ?>
 158  
 159          <figure class="post-thumbnail">
 160              <a class="post-thumbnail-inner" href="<?php the_permalink(); ?>" aria-hidden="true" tabindex="-1">
 161                  <?php the_post_thumbnail( 'post-thumbnail' ); ?>
 162              </a>
 163          </figure>
 164  
 165              <?php
 166          endif; // End is_singular().
 167      }
 168  endif;
 169  
 170  if ( ! function_exists( 'twentynineteen_get_user_avatar_markup' ) ) :
 171      /**
 172       * Returns the HTML markup to generate a user avatar.
 173       */
 174  	function twentynineteen_get_user_avatar_markup( $id_or_email = null ) {
 175  
 176          if ( ! isset( $id_or_email ) ) {
 177              $id_or_email = get_current_user_id();
 178          }
 179  
 180          return sprintf( '<div class="comment-user-avatar comment-author vcard">%s</div>', get_avatar( $id_or_email, twentynineteen_get_avatar_size() ) );
 181      }
 182  endif;
 183  
 184  if ( ! function_exists( 'twentynineteen_discussion_avatars_list' ) ) :
 185      /**
 186       * Displays a list of avatars involved in a discussion for a given post.
 187       */
 188  	function twentynineteen_discussion_avatars_list( $comment_authors ) {
 189          if ( empty( $comment_authors ) ) {
 190              return;
 191          }
 192          echo '<ol class="discussion-avatar-list">', "\n";
 193          foreach ( $comment_authors as $id_or_email ) {
 194              printf(
 195                  "<li>%s</li>\n",
 196                  twentynineteen_get_user_avatar_markup( $id_or_email )
 197              );
 198          }
 199          echo '</ol><!-- .discussion-avatar-list -->', "\n";
 200      }
 201  endif;
 202  
 203  if ( ! function_exists( 'twentynineteen_comment_form' ) ) :
 204      /**
 205       * Documentation for function.
 206       */
 207  	function twentynineteen_comment_form( $order ) {
 208          if ( true === $order || strtolower( $order ) === strtolower( get_option( 'comment_order', 'asc' ) ) ) {
 209  
 210              comment_form(
 211                  array(
 212                      'title_reply' => null,
 213                  )
 214              );
 215          }
 216      }
 217  endif;
 218  
 219  if ( ! function_exists( 'twentynineteen_the_posts_navigation' ) ) :
 220      /**
 221       * Documentation for function.
 222       */
 223  	function twentynineteen_the_posts_navigation() {
 224          the_posts_pagination(
 225              array(
 226                  'mid_size'  => 2,
 227                  'prev_text' => sprintf(
 228                      '%s <span class="nav-prev-text">%s</span>',
 229                      twentynineteen_get_icon_svg( 'chevron_left', 22 ),
 230                      __( 'Newer posts', 'twentynineteen' )
 231                  ),
 232                  'next_text' => sprintf(
 233                      '<span class="nav-next-text">%s</span> %s',
 234                      __( 'Older posts', 'twentynineteen' ),
 235                      twentynineteen_get_icon_svg( 'chevron_right', 22 )
 236                  ),
 237              )
 238          );
 239      }
 240  endif;
 241  
 242  if ( ! function_exists( 'wp_body_open' ) ) :
 243      /**
 244       * Fire the wp_body_open action.
 245       *
 246       * Added for backward compatibility to support pre-5.2.0 WordPress versions.
 247       *
 248       * @since Twenty Nineteen 1.4
 249       */
 250  	function wp_body_open() {
 251          /**
 252           * Triggered after the opening <body> tag.
 253           *
 254           * @since Twenty Nineteen 1.4
 255           */
 256          do_action( 'wp_body_open' );
 257      }
 258  endif;


Generated : Mon Mar 18 08:20:01 2024 Cross-referenced by PHPXref