[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Custom template tags for Twenty Fourteen
   4   *
   5   * @package WordPress
   6   * @subpackage Twenty_Fourteen
   7   * @since Twenty Fourteen 1.0
   8   */
   9  
  10  if ( ! function_exists( 'twentyfourteen_paging_nav' ) ) :
  11      /**
  12       * Display navigation to next/previous set of posts when applicable.
  13       *
  14       * @since Twenty Fourteen 1.0
  15       *
  16       * @global WP_Query   $wp_query   WordPress Query object.
  17       * @global WP_Rewrite $wp_rewrite WordPress Rewrite object.
  18       */
  19  	function twentyfourteen_paging_nav() {
  20          global $wp_query, $wp_rewrite;
  21  
  22          // Don't print empty markup if there's only one page.
  23          if ( $wp_query->max_num_pages < 2 ) {
  24              return;
  25          }
  26  
  27          $paged        = get_query_var( 'paged' ) ? (int) get_query_var( 'paged' ) : 1;
  28          $pagenum_link = html_entity_decode( get_pagenum_link() );
  29          $query_args   = array();
  30          $url_parts    = explode( '?', $pagenum_link );
  31  
  32          if ( isset( $url_parts[1] ) ) {
  33              wp_parse_str( $url_parts[1], $query_args );
  34          }
  35  
  36          $pagenum_link = remove_query_arg( array_keys( $query_args ), $pagenum_link );
  37          $pagenum_link = trailingslashit( $pagenum_link ) . '%_%';
  38  
  39          $format  = $wp_rewrite->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : '';
  40          $format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?paged=%#%';
  41  
  42          // Set up paginated links.
  43          $links = paginate_links(
  44              array(
  45                  'base'      => $pagenum_link,
  46                  'format'    => $format,
  47                  'total'     => $wp_query->max_num_pages,
  48                  'current'   => $paged,
  49                  'mid_size'  => 1,
  50                  'add_args'  => array_map( 'urlencode', $query_args ),
  51                  'prev_text' => __( '&larr; Previous', 'twentyfourteen' ),
  52                  'next_text' => __( 'Next &rarr;', 'twentyfourteen' ),
  53              )
  54          );
  55  
  56          if ( $links ) :
  57  
  58              ?>
  59          <nav class="navigation paging-navigation">
  60          <h1 class="screen-reader-text">
  61              <?php
  62              /* translators: Hidden accessibility text. */
  63              _e( 'Posts navigation', 'twentyfourteen' );
  64              ?>
  65          </h1>
  66          <div class="pagination loop-pagination">
  67              <?php echo $links; ?>
  68          </div><!-- .pagination -->
  69      </nav><!-- .navigation -->
  70              <?php
  71      endif;
  72      }
  73  endif;
  74  
  75  if ( ! function_exists( 'twentyfourteen_post_nav' ) ) :
  76      /**
  77       * Display navigation to next/previous post when applicable.
  78       *
  79       * @since Twenty Fourteen 1.0
  80       */
  81  	function twentyfourteen_post_nav() {
  82          // Don't print empty markup if there's nowhere to navigate.
  83          $previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
  84          $next     = get_adjacent_post( false, '', false );
  85  
  86          if ( ! $next && ! $previous ) {
  87              return;
  88          }
  89  
  90          ?>
  91          <nav class="navigation post-navigation">
  92          <h1 class="screen-reader-text">
  93              <?php
  94              /* translators: Hidden accessibility text. */
  95              _e( 'Post navigation', 'twentyfourteen' );
  96              ?>
  97          </h1>
  98          <div class="nav-links">
  99              <?php
 100              if ( is_attachment() ) :
 101                  previous_post_link( '%link', __( '<span class="meta-nav">Published In</span>%title', 'twentyfourteen' ) );
 102                  else :
 103                      previous_post_link( '%link', __( '<span class="meta-nav">Previous Post</span>%title', 'twentyfourteen' ) );
 104                      next_post_link( '%link', __( '<span class="meta-nav">Next Post</span>%title', 'twentyfourteen' ) );
 105                  endif;
 106                  ?>
 107              </div><!-- .nav-links -->
 108          </nav><!-- .navigation -->
 109          <?php
 110      }
 111  endif;
 112  
 113  if ( ! function_exists( 'twentyfourteen_posted_on' ) ) :
 114      /**
 115       * Print HTML with meta information for the current post-date/time and author.
 116       *
 117       * @since Twenty Fourteen 1.0
 118       */
 119  	function twentyfourteen_posted_on() {
 120          if ( is_sticky() && is_home() && ! is_paged() ) {
 121              echo '<span class="featured-post">' . __( 'Sticky', 'twentyfourteen' ) . '</span>';
 122          }
 123  
 124          // Set up and print post meta information.
 125          printf(
 126              '<span class="entry-date"><a href="%1$s" rel="bookmark"><time class="entry-date" datetime="%2$s">%3$s</time></a></span> <span class="byline"><span class="author vcard"><a class="url fn n" href="%4$s" rel="author">%5$s</a></span></span>',
 127              esc_url( get_permalink() ),
 128              esc_attr( get_the_date( 'c' ) ),
 129              esc_html( get_the_date() ),
 130              esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
 131              get_the_author()
 132          );
 133      }
 134  endif;
 135  
 136  /**
 137   * Find out if blog has more than one category.
 138   *
 139   * @since Twenty Fourteen 1.0
 140   *
 141   * @return bool true if blog has more than 1 category
 142   */
 143  function twentyfourteen_categorized_blog() {
 144      $all_the_cool_cats = get_transient( 'twentyfourteen_category_count' );
 145      if ( false === $all_the_cool_cats ) {
 146          // Create an array of all the categories that are attached to posts.
 147          $all_the_cool_cats = get_categories(
 148              array(
 149                  'hide_empty' => 1,
 150              )
 151          );
 152  
 153          // Count the number of categories that are attached to the posts.
 154          $all_the_cool_cats = count( $all_the_cool_cats );
 155  
 156          set_transient( 'twentyfourteen_category_count', $all_the_cool_cats );
 157      }
 158  
 159      if ( $all_the_cool_cats > 1 || is_preview() ) {
 160          // This blog has more than 1 category so twentyfourteen_categorized_blog() should return true.
 161          return true;
 162      } else {
 163          // This blog has only 1 category so twentyfourteen_categorized_blog() should return false.
 164          return false;
 165      }
 166  }
 167  
 168  /**
 169   * Flush out the transients used in twentyfourteen_categorized_blog.
 170   *
 171   * @since Twenty Fourteen 1.0
 172   */
 173  function twentyfourteen_category_transient_flusher() {
 174      // Like, beat it. Dig?
 175      delete_transient( 'twentyfourteen_category_count' );
 176  }
 177  add_action( 'edit_category', 'twentyfourteen_category_transient_flusher' );
 178  add_action( 'save_post', 'twentyfourteen_category_transient_flusher' );
 179  
 180  if ( ! function_exists( 'twentyfourteen_post_thumbnail' ) ) :
 181      /**
 182       * Display an optional post thumbnail.
 183       *
 184       * Wraps the post thumbnail in an anchor element on index
 185       * views, or a div element when on single views.
 186       *
 187       * @since Twenty Fourteen 1.0
 188       * @since Twenty Fourteen 1.4 Was made 'pluggable', or overridable.
 189       */
 190  	function twentyfourteen_post_thumbnail() {
 191          if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) {
 192              return;
 193          }
 194  
 195          if ( is_singular() ) :
 196              ?>
 197  
 198          <div class="post-thumbnail">
 199              <?php
 200              if ( ( ! is_active_sidebar( 'sidebar-2' ) || is_page_template( 'page-templates/full-width.php' ) ) ) {
 201                  the_post_thumbnail( 'twentyfourteen-full-width' );
 202              } else {
 203                  the_post_thumbnail();
 204              }
 205              ?>
 206          </div>
 207  
 208          <?php else : ?>
 209  
 210      <a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true">
 211              <?php
 212              if ( ( ! is_active_sidebar( 'sidebar-2' ) || is_page_template( 'page-templates/full-width.php' ) ) ) {
 213                  the_post_thumbnail( 'twentyfourteen-full-width' );
 214              } else {
 215                  the_post_thumbnail( 'post-thumbnail', array( 'alt' => get_the_title() ) );
 216              }
 217              ?>
 218      </a>
 219  
 220              <?php
 221      endif; // End is_singular().
 222      }
 223  endif;
 224  
 225  if ( ! function_exists( 'twentyfourteen_excerpt_more' ) && ! is_admin() ) :
 226      /**
 227       * Replaces "[...]" (appended to automatically generated excerpts) with ...
 228       * and a Continue reading link.
 229       *
 230       * @since Twenty Fourteen 1.3
 231       *
 232       * @param string $more Default Read More excerpt link.
 233       * @return string Filtered Read More excerpt link.
 234       */
 235  	function twentyfourteen_excerpt_more( $more ) {
 236          $link = sprintf(
 237              '<a href="%1$s" class="more-link">%2$s</a>',
 238              esc_url( get_permalink( get_the_ID() ) ),
 239              /* translators: %s: Post title. Only visible to screen readers. */
 240              sprintf( __( 'Continue reading %s <span class="meta-nav">&rarr;</span>', 'twentyfourteen' ), '<span class="screen-reader-text">' . get_the_title( get_the_ID() ) . '</span>' )
 241          );
 242          return ' &hellip; ' . $link;
 243      }
 244      add_filter( 'excerpt_more', 'twentyfourteen_excerpt_more' );
 245  endif;
 246  
 247  if ( ! function_exists( 'wp_body_open' ) ) :
 248      /**
 249       * Fire the wp_body_open action.
 250       *
 251       * Added for backward compatibility to support pre-5.2.0 WordPress versions.
 252       *
 253       * @since Twenty Fourteen 2.7
 254       */
 255  	function wp_body_open() {
 256          /**
 257           * Triggered after the opening <body> tag.
 258           *
 259           * @since Twenty Fourteen 2.7
 260           */
 261          do_action( 'wp_body_open' );
 262      }
 263  endif;


Generated : Thu May 9 08:20:02 2024 Cross-referenced by PHPXref