[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Custom template tags for this theme
   4   *
   5   * @package WordPress
   6   * @subpackage Twenty_Twenty_One
   7   * @since Twenty Twenty-One 1.0
   8   */
   9  
  10  if ( ! function_exists( 'twenty_twenty_one_posted_on' ) ) {
  11      /**
  12       * Prints HTML with meta information for the current post-date/time.
  13       *
  14       * @since Twenty Twenty-One 1.0
  15       *
  16       * @return void
  17       */
  18  	function twenty_twenty_one_posted_on() {
  19          $time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
  20  
  21          $time_string = sprintf(
  22              $time_string,
  23              esc_attr( get_the_date( DATE_W3C ) ),
  24              esc_html( get_the_date() )
  25          );
  26          echo '<span class="posted-on">';
  27          printf(
  28              /* translators: %s: Publish date. */
  29              esc_html__( 'Published %s', 'twentytwentyone' ),
  30              $time_string // phpcs:ignore WordPress.Security.EscapeOutput
  31          );
  32          echo '</span>';
  33      }
  34  }
  35  
  36  if ( ! function_exists( 'twenty_twenty_one_posted_by' ) ) {
  37      /**
  38       * Prints HTML with meta information about theme author.
  39       *
  40       * @since Twenty Twenty-One 1.0
  41       *
  42       * @return void
  43       */
  44  	function twenty_twenty_one_posted_by() {
  45          if ( ! get_the_author_meta( 'description' ) && post_type_supports( get_post_type(), 'author' ) ) {
  46              echo '<span class="byline">';
  47              printf(
  48                  /* translators: %s: Author name. */
  49                  esc_html__( 'By %s', 'twentytwentyone' ),
  50                  '<a href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '" rel="author">' . esc_html( get_the_author() ) . '</a>'
  51              );
  52              echo '</span>';
  53          }
  54      }
  55  }
  56  
  57  if ( ! function_exists( 'twenty_twenty_one_entry_meta_footer' ) ) {
  58      /**
  59       * Prints HTML with meta information for the categories, tags and comments.
  60       * Footer entry meta is displayed differently in archives and single posts.
  61       *
  62       * @since Twenty Twenty-One 1.0
  63       *
  64       * @return void
  65       */
  66  	function twenty_twenty_one_entry_meta_footer() {
  67  
  68          // Early exit if not a post.
  69          if ( 'post' !== get_post_type() ) {
  70              return;
  71          }
  72  
  73          // Hide meta information on pages.
  74          if ( ! is_single() ) {
  75  
  76              if ( is_sticky() ) {
  77                  echo '<p>' . esc_html_x( 'Featured post', 'Label for sticky posts', 'twentytwentyone' ) . '</p>';
  78              }
  79  
  80              $post_format = get_post_format();
  81              if ( 'aside' === $post_format || 'status' === $post_format ) {
  82                  echo '<p><a href="' . esc_url( get_permalink() ) . '">' . twenty_twenty_one_continue_reading_text() . '</a></p>'; // phpcs:ignore WordPress.Security.EscapeOutput
  83              }
  84  
  85              // Posted on.
  86              twenty_twenty_one_posted_on();
  87  
  88              // Edit post link.
  89              edit_post_link(
  90                  sprintf(
  91                      /* translators: %s: Name of current post. Only visible to screen readers. */
  92                      esc_html__( 'Edit %s', 'twentytwentyone' ),
  93                      '<span class="screen-reader-text">' . get_the_title() . '</span>'
  94                  ),
  95                  '<span class="edit-link">',
  96                  '</span><br>'
  97              );
  98  
  99              if ( has_category() || has_tag() ) {
 100  
 101                  echo '<div class="post-taxonomies">';
 102  
 103                  /* translators: Used between list items, there is a space after the comma. */
 104                  $categories_list = get_the_category_list( __( ', ', 'twentytwentyone' ) );
 105                  if ( $categories_list ) {
 106                      printf(
 107                          /* translators: %s: List of categories. */
 108                          '<span class="cat-links">' . esc_html__( 'Categorized as %s', 'twentytwentyone' ) . ' </span>',
 109                          $categories_list // phpcs:ignore WordPress.Security.EscapeOutput
 110                      );
 111                  }
 112  
 113                  /* translators: Used between list items, there is a space after the comma. */
 114                  $tags_list = get_the_tag_list( '', __( ', ', 'twentytwentyone' ) );
 115                  if ( $tags_list ) {
 116                      printf(
 117                          /* translators: %s: List of tags. */
 118                          '<span class="tags-links">' . esc_html__( 'Tagged %s', 'twentytwentyone' ) . '</span>',
 119                          $tags_list // phpcs:ignore WordPress.Security.EscapeOutput
 120                      );
 121                  }
 122                  echo '</div>';
 123              }
 124          } else {
 125  
 126              echo '<div class="posted-by">';
 127              // Posted on.
 128              twenty_twenty_one_posted_on();
 129              // Posted by.
 130              twenty_twenty_one_posted_by();
 131              // Edit post link.
 132              edit_post_link(
 133                  sprintf(
 134                      /* translators: %s: Name of current post. Only visible to screen readers. */
 135                      esc_html__( 'Edit %s', 'twentytwentyone' ),
 136                      '<span class="screen-reader-text">' . get_the_title() . '</span>'
 137                  ),
 138                  '<span class="edit-link">',
 139                  '</span>'
 140              );
 141              echo '</div>';
 142  
 143              if ( has_category() || has_tag() ) {
 144  
 145                  echo '<div class="post-taxonomies">';
 146  
 147                  /* translators: Used between list items, there is a space after the comma. */
 148                  $categories_list = get_the_category_list( __( ', ', 'twentytwentyone' ) );
 149                  if ( $categories_list ) {
 150                      printf(
 151                          /* translators: %s: List of categories. */
 152                          '<span class="cat-links">' . esc_html__( 'Categorized as %s', 'twentytwentyone' ) . ' </span>',
 153                          $categories_list // phpcs:ignore WordPress.Security.EscapeOutput
 154                      );
 155                  }
 156  
 157                  /* translators: Used between list items, there is a space after the comma. */
 158                  $tags_list = get_the_tag_list( '', __( ', ', 'twentytwentyone' ) );
 159                  if ( $tags_list ) {
 160                      printf(
 161                          /* translators: %s: List of tags. */
 162                          '<span class="tags-links">' . esc_html__( 'Tagged %s', 'twentytwentyone' ) . '</span>',
 163                          $tags_list // phpcs:ignore WordPress.Security.EscapeOutput
 164                      );
 165                  }
 166                  echo '</div>';
 167              }
 168          }
 169      }
 170  }
 171  
 172  if ( ! function_exists( 'twenty_twenty_one_post_thumbnail' ) ) {
 173      /**
 174       * Displays an optional post thumbnail.
 175       *
 176       * Wraps the post thumbnail in an anchor element on index views, or a div
 177       * element when on single views.
 178       *
 179       * @since Twenty Twenty-One 1.0
 180       *
 181       * @return void
 182       */
 183  	function twenty_twenty_one_post_thumbnail() {
 184          if ( ! twenty_twenty_one_can_show_post_thumbnail() ) {
 185              return;
 186          }
 187          ?>
 188  
 189          <?php if ( is_singular() ) : ?>
 190  
 191              <figure class="post-thumbnail">
 192                  <?php
 193                  // Lazy-loading attributes should be skipped for thumbnails since they are immediately in the viewport.
 194                  the_post_thumbnail( 'post-thumbnail', array( 'loading' => false ) );
 195                  ?>
 196                  <?php if ( wp_get_attachment_caption( get_post_thumbnail_id() ) ) : ?>
 197                      <figcaption class="wp-caption-text"><?php echo wp_kses_post( wp_get_attachment_caption( get_post_thumbnail_id() ) ); ?></figcaption>
 198                  <?php endif; ?>
 199              </figure><!-- .post-thumbnail -->
 200  
 201          <?php else : ?>
 202  
 203              <figure class="post-thumbnail">
 204                  <a class="post-thumbnail-inner alignwide" href="<?php the_permalink(); ?>" aria-hidden="true" tabindex="-1">
 205                      <?php the_post_thumbnail( 'post-thumbnail' ); ?>
 206                  </a>
 207                  <?php if ( wp_get_attachment_caption( get_post_thumbnail_id() ) ) : ?>
 208                      <figcaption class="wp-caption-text"><?php echo wp_kses_post( wp_get_attachment_caption( get_post_thumbnail_id() ) ); ?></figcaption>
 209                  <?php endif; ?>
 210              </figure>
 211  
 212          <?php endif; ?>
 213          <?php
 214      }
 215  }
 216  
 217  if ( ! function_exists( 'twenty_twenty_one_the_posts_navigation' ) ) {
 218      /**
 219       * Print the next and previous posts navigation.
 220       *
 221       * @since Twenty Twenty-One 1.0
 222       *
 223       * @return void
 224       */
 225  	function twenty_twenty_one_the_posts_navigation() {
 226          the_posts_pagination(
 227              array(
 228                  'before_page_number' => esc_html__( 'Page', 'twentytwentyone' ) . ' ',
 229                  'mid_size'           => 0,
 230                  'prev_text'          => sprintf(
 231                      '%s <span class="nav-prev-text">%s</span>',
 232                      is_rtl() ? twenty_twenty_one_get_icon_svg( 'ui', 'arrow_right' ) : twenty_twenty_one_get_icon_svg( 'ui', 'arrow_left' ),
 233                      wp_kses(
 234                          __( 'Newer <span class="nav-short">posts</span>', 'twentytwentyone' ),
 235                          array(
 236                              'span' => array(
 237                                  'class' => array(),
 238                              ),
 239                          )
 240                      )
 241                  ),
 242                  'next_text'          => sprintf(
 243                      '<span class="nav-next-text">%s</span> %s',
 244                      wp_kses(
 245                          __( 'Older <span class="nav-short">posts</span>', 'twentytwentyone' ),
 246                          array(
 247                              'span' => array(
 248                                  'class' => array(),
 249                              ),
 250                          )
 251                      ),
 252                      is_rtl() ? twenty_twenty_one_get_icon_svg( 'ui', 'arrow_left' ) : twenty_twenty_one_get_icon_svg( 'ui', 'arrow_right' )
 253                  ),
 254              )
 255          );
 256      }
 257  }


Generated: Sat May 15 01:00:05 2021 Cross-referenced by PHPXref 0.7.1