[ Index ]

WordPress Cross Reference

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   * @return void
  17   */
  18  function twentyfourteen_paging_nav() {
  19      // Don't print empty markup if there's only one page.
  20      if ( $GLOBALS['wp_query']->max_num_pages < 2 ) {
  21          return;
  22      }
  23  
  24      $paged        = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1;
  25      $pagenum_link = html_entity_decode( get_pagenum_link() );
  26      $query_args   = array();
  27      $url_parts    = explode( '?', $pagenum_link );
  28  
  29      if ( isset( $url_parts[1] ) ) {
  30          wp_parse_str( $url_parts[1], $query_args );
  31      }
  32  
  33      $pagenum_link = remove_query_arg( array_keys( $query_args ), $pagenum_link );
  34      $pagenum_link = trailingslashit( $pagenum_link ) . '%_%';
  35  
  36      $format  = $GLOBALS['wp_rewrite']->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : '';
  37      $format .= $GLOBALS['wp_rewrite']->using_permalinks() ? user_trailingslashit( 'page/%#%', 'paged' ) : '?paged=%#%';
  38  
  39      // Set up paginated links.
  40      $links = paginate_links( array(
  41          'base'     => $pagenum_link,
  42          'format'   => $format,
  43          'total'    => $GLOBALS['wp_query']->max_num_pages,
  44          'current'  => $paged,
  45          'mid_size' => 1,
  46          'add_args' => array_map( 'urlencode', $query_args ),
  47          'prev_text' => __( '&larr; Previous', 'twentyfourteen' ),
  48          'next_text' => __( 'Next &rarr;', 'twentyfourteen' ),
  49      ) );
  50  
  51      if ( $links ) :
  52  
  53      ?>
  54      <nav class="navigation paging-navigation" role="navigation">
  55          <h1 class="screen-reader-text"><?php _e( 'Posts navigation', 'twentyfourteen' ); ?></h1>
  56          <div class="pagination loop-pagination">
  57              <?php echo $links; ?>
  58          </div><!-- .pagination -->
  59      </nav><!-- .navigation -->
  60      <?php
  61      endif;
  62  }
  63  endif;
  64  
  65  if ( ! function_exists( 'twentyfourteen_post_nav' ) ) :
  66  /**
  67   * Display navigation to next/previous post when applicable.
  68   *
  69   * @since Twenty Fourteen 1.0
  70   *
  71   * @return void
  72   */
  73  function twentyfourteen_post_nav() {
  74      // Don't print empty markup if there's nowhere to navigate.
  75      $previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
  76      $next     = get_adjacent_post( false, '', false );
  77  
  78      if ( ! $next && ! $previous ) {
  79          return;
  80      }
  81  
  82      ?>
  83      <nav class="navigation post-navigation" role="navigation">
  84          <h1 class="screen-reader-text"><?php _e( 'Post navigation', 'twentyfourteen' ); ?></h1>
  85          <div class="nav-links">
  86              <?php
  87              if ( is_attachment() ) :
  88                  previous_post_link( '%link', __( '<span class="meta-nav">Published In</span>%title', 'twentyfourteen' ) );
  89              else :
  90                  previous_post_link( '%link', __( '<span class="meta-nav">Previous Post</span>%title', 'twentyfourteen' ) );
  91                  next_post_link( '%link', __( '<span class="meta-nav">Next Post</span>%title', 'twentyfourteen' ) );
  92              endif;
  93              ?>
  94          </div><!-- .nav-links -->
  95      </nav><!-- .navigation -->
  96      <?php
  97  }
  98  endif;
  99  
 100  if ( ! function_exists( 'twentyfourteen_posted_on' ) ) :
 101  /**
 102   * Print HTML with meta information for the current post-date/time and author.
 103   *
 104   * @since Twenty Fourteen 1.0
 105   *
 106   * @return void
 107   */
 108  function twentyfourteen_posted_on() {
 109      if ( is_sticky() && is_home() && ! is_paged() ) {
 110          echo '<span class="featured-post">' . __( 'Sticky', 'twentyfourteen' ) . '</span>';
 111      }
 112  
 113      // Set up and print post meta information.
 114      printf( '<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>',
 115          esc_url( get_permalink() ),
 116          esc_attr( get_the_date( 'c' ) ),
 117          esc_html( get_the_date() ),
 118          esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
 119          get_the_author()
 120      );
 121  }
 122  endif;
 123  
 124  /**
 125   * Find out if blog has more than one category.
 126   *
 127   * @since Twenty Fourteen 1.0
 128   *
 129   * @return boolean true if blog has more than 1 category
 130   */
 131  function twentyfourteen_categorized_blog() {
 132      if ( false === ( $all_the_cool_cats = get_transient( 'twentyfourteen_category_count' ) ) ) {
 133          // Create an array of all the categories that are attached to posts
 134          $all_the_cool_cats = get_categories( array(
 135              'hide_empty' => 1,
 136          ) );
 137  
 138          // Count the number of categories that are attached to the posts
 139          $all_the_cool_cats = count( $all_the_cool_cats );
 140  
 141          set_transient( 'twentyfourteen_category_count', $all_the_cool_cats );
 142      }
 143  
 144      if ( 1 !== (int) $all_the_cool_cats ) {
 145          // This blog has more than 1 category so twentyfourteen_categorized_blog should return true
 146          return true;
 147      } else {
 148          // This blog has only 1 category so twentyfourteen_categorized_blog should return false
 149          return false;
 150      }
 151  }
 152  
 153  /**
 154   * Flush out the transients used in twentyfourteen_categorized_blog.
 155   *
 156   * @since Twenty Fourteen 1.0
 157   *
 158   * @return void
 159   */
 160  function twentyfourteen_category_transient_flusher() {
 161      // Like, beat it. Dig?
 162      delete_transient( 'twentyfourteen_category_count' );
 163  }
 164  add_action( 'edit_category', 'twentyfourteen_category_transient_flusher' );
 165  add_action( 'save_post',     'twentyfourteen_category_transient_flusher' );
 166  
 167  /**
 168   * Display an optional post thumbnail.
 169   *
 170   * Wraps the post thumbnail in an anchor element on index
 171   * views, or a div element when on single views.
 172   *
 173   * @since Twenty Fourteen 1.0
 174   *
 175   * @return void
 176  */
 177  function twentyfourteen_post_thumbnail() {
 178      if ( post_password_required() || ! has_post_thumbnail() ) {
 179          return;
 180      }
 181  
 182      if ( is_singular() ) :
 183      ?>
 184  
 185      <div class="post-thumbnail">
 186      <?php
 187          if ( ( ! is_active_sidebar( 'sidebar-2' ) || is_page_template( 'page-templates/full-width.php' ) ) ) {
 188              the_post_thumbnail( 'twentyfourteen-full-width' );
 189          } else {
 190              the_post_thumbnail();
 191          }
 192      ?>
 193      </div>
 194  
 195      <?php else : ?>
 196  
 197      <a class="post-thumbnail" href="<?php the_permalink(); ?>">
 198      <?php
 199          if ( ( ! is_active_sidebar( 'sidebar-2' ) || is_page_template( 'page-templates/full-width.php' ) ) ) {
 200              the_post_thumbnail( 'twentyfourteen-full-width' );
 201          } else {
 202              the_post_thumbnail();
 203          }
 204      ?>
 205      </a>
 206  
 207      <?php endif; // End is_singular()
 208  }


Generated: Tue Mar 25 01:41:18 2014 WordPress honlapkészítés: online1.hu