[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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

   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 WordPress
   8   * @subpackage Twenty_Seventeen
   9   * @since 1.0
  10   */
  11  
  12  if ( ! function_exists( 'twentyseventeen_posted_on' ) ) :
  13      /**
  14       * Prints HTML with meta information for the current post-date/time and author.
  15       */
  16  	function twentyseventeen_posted_on() {
  17  
  18          // Get the author name; wrap it in a link.
  19          $byline = sprintf(
  20              /* translators: %s: Post author. */
  21              __( 'by %s', 'twentyseventeen' ),
  22              '<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . get_the_author() . '</a></span>'
  23          );
  24  
  25          // Finally, let's write all of this to the page.
  26          echo '<span class="posted-on">' . twentyseventeen_time_link() . '</span><span class="byline"> ' . $byline . '</span>';
  27      }
  28  endif;
  29  
  30  
  31  if ( ! function_exists( 'twentyseventeen_time_link' ) ) :
  32      /**
  33       * Gets a nicely formatted string for the published date.
  34       */
  35  	function twentyseventeen_time_link() {
  36          $time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
  37          if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
  38              $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
  39          }
  40  
  41          $time_string = sprintf(
  42              $time_string,
  43              get_the_date( DATE_W3C ),
  44              get_the_date(),
  45              get_the_modified_date( DATE_W3C ),
  46              get_the_modified_date()
  47          );
  48  
  49          // Wrap the time string in a link, and preface it with 'Posted on'.
  50          return sprintf(
  51              /* translators: %s: Post date. */
  52              __( '<span class="screen-reader-text">Posted on</span> %s', 'twentyseventeen' ),
  53              '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
  54          );
  55      }
  56  endif;
  57  
  58  
  59  if ( ! function_exists( 'twentyseventeen_entry_footer' ) ) :
  60      /**
  61       * Prints HTML with meta information for the categories, tags and comments.
  62       */
  63  	function twentyseventeen_entry_footer() {
  64  
  65          /* translators: Used between list items, there is a space after the comma. */
  66          $separate_meta = __( ', ', 'twentyseventeen' );
  67  
  68          // Get Categories for posts.
  69          $categories_list = get_the_category_list( $separate_meta );
  70  
  71          // Get Tags for posts.
  72          $tags_list = get_the_tag_list( '', $separate_meta );
  73  
  74          // We don't want to output .entry-footer if it will be empty, so make sure its not.
  75          if ( ( ( twentyseventeen_categorized_blog() && $categories_list ) || $tags_list ) || get_edit_post_link() ) {
  76  
  77              echo '<footer class="entry-footer">';
  78  
  79              if ( 'post' === get_post_type() ) {
  80                  if ( ( $categories_list && twentyseventeen_categorized_blog() ) || $tags_list ) {
  81                      echo '<span class="cat-tags-links">';
  82  
  83                          // Make sure there's more than one category before displaying.
  84                      if ( $categories_list && twentyseventeen_categorized_blog() ) {
  85                          echo '<span class="cat-links">' . twentyseventeen_get_svg( array( 'icon' => 'folder-open' ) ) . '<span class="screen-reader-text">' . __( 'Categories', 'twentyseventeen' ) . '</span>' . $categories_list . '</span>';
  86                      }
  87  
  88                      if ( $tags_list && ! is_wp_error( $tags_list ) ) {
  89                          echo '<span class="tags-links">' . twentyseventeen_get_svg( array( 'icon' => 'hashtag' ) ) . '<span class="screen-reader-text">' . __( 'Tags', 'twentyseventeen' ) . '</span>' . $tags_list . '</span>';
  90                      }
  91  
  92                      echo '</span>';
  93                  }
  94              }
  95  
  96              twentyseventeen_edit_link();
  97  
  98              echo '</footer> <!-- .entry-footer -->';
  99          }
 100      }
 101  endif;
 102  
 103  
 104  if ( ! function_exists( 'twentyseventeen_edit_link' ) ) :
 105      /**
 106       * Returns an accessibility-friendly link to edit a post or page.
 107       *
 108       * This also gives us a little context about what exactly we're editing
 109       * (post or page?) so that users understand a bit more where they are in terms
 110       * of the template hierarchy and their content. Helpful when/if the single-page
 111       * layout with multiple posts/pages shown gets confusing.
 112       */
 113  	function twentyseventeen_edit_link() {
 114          edit_post_link(
 115              sprintf(
 116                  /* translators: %s: Post title. */
 117                  __( 'Edit<span class="screen-reader-text"> "%s"</span>', 'twentyseventeen' ),
 118                  get_the_title()
 119              ),
 120              '<span class="edit-link">',
 121              '</span>'
 122          );
 123      }
 124  endif;
 125  
 126  /**
 127   * Display a front page section.
 128   *
 129   * @param WP_Customize_Partial $partial Partial associated with a selective refresh request.
 130   * @param integer              $id Front page section to display.
 131   */
 132  function twentyseventeen_front_page_section( $partial = null, $id = 0 ) {
 133      if ( is_a( $partial, 'WP_Customize_Partial' ) ) {
 134          // Find out the id and set it up during a selective refresh.
 135          global $twentyseventeencounter;
 136          $id                     = str_replace( 'panel_', '', $partial->id );
 137          $twentyseventeencounter = $id;
 138      }
 139  
 140      global $post; // Modify the global post object before setting up post data.
 141      if ( get_theme_mod( 'panel_' . $id ) ) {
 142          $post = get_post( get_theme_mod( 'panel_' . $id ) );
 143          setup_postdata( $post );
 144          set_query_var( 'panel', $id );
 145  
 146          get_template_part( 'template-parts/page/content', 'front-page-panels' );
 147  
 148          wp_reset_postdata();
 149      } elseif ( is_customize_preview() ) {
 150          // The output placeholder anchor.
 151          /* translators: %s: The section ID. */
 152          echo '<article class="panel-placeholder panel twentyseventeen-panel twentyseventeen-panel' . $id . '" id="panel' . $id . '"><span class="twentyseventeen-panel-title">' . sprintf( __( 'Front Page Section %s Placeholder', 'twentyseventeen' ), $id ) . '</span></article>';
 153      }
 154  }
 155  
 156  /**
 157   * Returns true if a blog has more than 1 category.
 158   *
 159   * @return bool
 160   */
 161  function twentyseventeen_categorized_blog() {
 162      $category_count = get_transient( 'twentyseventeen_categories' );
 163  
 164      if ( false === $category_count ) {
 165          // Create an array of all the categories that are attached to posts.
 166          $categories = get_categories(
 167              array(
 168                  'fields'     => 'ids',
 169                  'hide_empty' => 1,
 170                  // We only need to know if there is more than one category.
 171                  'number'     => 2,
 172              )
 173          );
 174  
 175          // Count the number of categories that are attached to the posts.
 176          $category_count = count( $categories );
 177  
 178          set_transient( 'twentyseventeen_categories', $category_count );
 179      }
 180  
 181      // Allow viewing case of 0 or 1 categories in post preview.
 182      if ( is_preview() ) {
 183          return true;
 184      }
 185  
 186      return $category_count > 1;
 187  }
 188  
 189  
 190  /**
 191   * Flush out the transients used in twentyseventeen_categorized_blog.
 192   */
 193  function twentyseventeen_category_transient_flusher() {
 194      if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
 195          return;
 196      }
 197      // Like, beat it. Dig?
 198      delete_transient( 'twentyseventeen_categories' );
 199  }
 200  add_action( 'edit_category', 'twentyseventeen_category_transient_flusher' );
 201  add_action( 'save_post', 'twentyseventeen_category_transient_flusher' );
 202  
 203  if ( ! function_exists( 'wp_body_open' ) ) :
 204      /**
 205       * Fire the wp_body_open action.
 206       *
 207       * Added for backwards compatibility to support pre 5.2.0 WordPress versions.
 208       *
 209       * @since Twenty Seventeen 2.2
 210       */
 211  	function wp_body_open() {
 212          /**
 213           * Triggered after the opening <body> tag.
 214           *
 215           * @since Twenty Seventeen 2.2
 216           */
 217          do_action( 'wp_body_open' );
 218      }
 219  endif;


Generated: Tue Sep 17 01:00:03 2019 Cross-referenced by PHPXref 0.7.1