[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-content/themes/twentyten/ -> loop.php (source)

   1  <?php
   2  /**
   3   * The loop that displays posts
   4   *
   5   * The loop displays the posts and the post content. See
   6   * https://developer.wordpress.org/themes/basics/the-loop/ to understand it and
   7   * https://developer.wordpress.org/themes/basics/template-tags/ to understand
   8   * the tags used in it.
   9   *
  10   * This can be overridden in child themes with loop.php or
  11   * loop-template.php, where 'template' is the loop context
  12   * requested by a template. For example, loop-index.php would
  13   * be used if it exists and we ask for the loop with:
  14   * <code>get_template_part( 'loop', 'index' );</code>
  15   *
  16   * @package WordPress
  17   * @subpackage Twenty_Ten
  18   * @since Twenty Ten 1.0
  19   */
  20  ?>
  21  
  22  <?php /* Display navigation to next/previous pages when applicable */ ?>
  23  <?php if ( $wp_query->max_num_pages > 1 ) : ?>
  24      <div id="nav-above" class="navigation">
  25          <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentyten' ) ); ?></div>
  26          <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?></div>
  27      </div><!-- #nav-above -->
  28  <?php endif; ?>
  29  
  30  <?php /* If there are no posts to display, such as an empty archive page */ ?>
  31  <?php if ( ! have_posts() ) : ?>
  32      <div id="post-0" class="post error404 not-found">
  33          <h1 class="entry-title"><?php _e( 'Not Found', 'twentyten' ); ?></h1>
  34          <div class="entry-content">
  35              <p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyten' ); ?></p>
  36              <?php get_search_form(); ?>
  37          </div><!-- .entry-content -->
  38      </div><!-- #post-0 -->
  39  <?php endif; ?>
  40  
  41  <?php
  42      /*
  43       * Start the Loop.
  44       *
  45       * In Twenty Ten we use the same loop in multiple contexts.
  46       * It is broken into three main parts: when we're displaying
  47       * posts that are in the gallery category, when we're displaying
  48       * posts in the asides category, and finally all other posts.
  49       *
  50       * Additionally, we sometimes check for whether we are on an
  51       * archive page, a search page, etc., allowing for small differences
  52       * in the loop on each template without actually duplicating
  53       * the rest of the loop that is shared.
  54       *
  55       * Without further ado, the loop:
  56       */
  57  ?>
  58  <?php
  59  while ( have_posts() ) :
  60      the_post();
  61      ?>
  62  
  63      <?php /* How to display posts of the Gallery format. The gallery category is the old way. */ ?>
  64  
  65      <?php if ( ( function_exists( 'get_post_format' ) && 'gallery' == get_post_format( $post->ID ) ) || in_category( _x( 'gallery', 'gallery category slug', 'twentyten' ) ) ) : ?>
  66          <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  67              <h2 class="entry-title"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
  68  
  69              <div class="entry-meta">
  70                  <?php twentyten_posted_on(); ?>
  71              </div><!-- .entry-meta -->
  72  
  73              <div class="entry-content">
  74          <?php if ( post_password_required() ) : ?>
  75                  <?php the_content(); ?>
  76  <?php else : ?>
  77                  <?php
  78                      $images = twentyten_get_gallery_images();
  79                  if ( $images ) :
  80                      $total_images = count( $images );
  81                      $image        = reset( $images );
  82                      ?>
  83                      <div class="gallery-thumb">
  84                          <a class="size-thumbnail" href="<?php the_permalink(); ?>"><?php echo wp_get_attachment_image( $image, 'thumbnail' ); ?></a>
  85                      </div><!-- .gallery-thumb -->
  86                      <p><em>
  87                      <?php
  88                          printf(
  89                              /* translators: 1: HTML tag attributes, 2: Image count. */
  90                              _n( 'This gallery contains <a %1$s>%2$s photo</a>.', 'This gallery contains <a %1$s>%2$s photos</a>.', $total_images, 'twentyten' ),
  91                              /* translators: %s: Post title. */
  92                              'href="' . esc_url( get_permalink() ) . '" title="' . esc_attr( sprintf( __( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ) ) . '" rel="bookmark"',
  93                              number_format_i18n( $total_images )
  94                          );
  95                      ?>
  96                              </em></p>
  97                  <?php endif; // end twentyten_get_gallery_images() check ?>
  98                          <?php the_excerpt(); ?>
  99  <?php endif; ?>
 100              </div><!-- .entry-content -->
 101  
 102              <div class="entry-utility">
 103              <?php
 104              $gallery = get_term_by( 'slug', _x( 'gallery', 'gallery category slug', 'twentyten' ), 'category' );
 105              if ( function_exists( 'get_post_format' ) && 'gallery' == get_post_format( $post->ID ) ) :
 106                  ?>
 107                  <a href="<?php echo esc_url( get_post_format_link( 'gallery' ) ); ?>" title="<?php esc_attr_e( 'View Galleries', 'twentyten' ); ?>"><?php _e( 'More Galleries', 'twentyten' ); ?></a>
 108                  <span class="meta-sep">|</span>
 109              <?php elseif ( $gallery && in_category( $gallery->term_id ) ) : ?>
 110                  <a href="<?php echo esc_url( get_category_link( $gallery ) ); ?>" title="<?php esc_attr_e( 'View posts in the Gallery category', 'twentyten' ); ?>"><?php _e( 'More Galleries', 'twentyten' ); ?></a>
 111                  <span class="meta-sep">|</span>
 112              <?php endif; ?>
 113                  <span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'twentyten' ), __( '1 Comment', 'twentyten' ), __( '% Comments', 'twentyten' ) ); ?></span>
 114                  <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?>
 115              </div><!-- .entry-utility -->
 116          </div><!-- #post-<?php the_ID(); ?> -->
 117  
 118          <?php /* How to display posts of the Aside format. The asides category is the old way. */ ?>
 119  
 120      <?php elseif ( ( function_exists( 'get_post_format' ) && 'aside' == get_post_format( $post->ID ) ) || in_category( _x( 'asides', 'asides category slug', 'twentyten' ) ) ) : ?>
 121          <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
 122  
 123          <?php if ( is_archive() || is_search() ) : // Display excerpts for archives and search. ?>
 124              <div class="entry-summary">
 125                  <?php the_excerpt(); ?>
 126              </div><!-- .entry-summary -->
 127          <?php else : ?>
 128              <div class="entry-content">
 129                  <?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?>
 130              </div><!-- .entry-content -->
 131          <?php endif; ?>
 132  
 133              <div class="entry-utility">
 134                  <?php twentyten_posted_on(); ?>
 135                  <span class="meta-sep">|</span>
 136                  <span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'twentyten' ), __( '1 Comment', 'twentyten' ), __( '% Comments', 'twentyten' ) ); ?></span>
 137                  <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?>
 138              </div><!-- .entry-utility -->
 139          </div><!-- #post-<?php the_ID(); ?> -->
 140  
 141          <?php /* How to display all other posts. */ ?>
 142  
 143      <?php else : ?>
 144          <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
 145              <h2 class="entry-title"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
 146  
 147              <div class="entry-meta">
 148                  <?php twentyten_posted_on(); ?>
 149              </div><!-- .entry-meta -->
 150  
 151          <?php if ( is_archive() || is_search() ) : // Only display excerpts for archives and search. ?>
 152              <div class="entry-summary">
 153                  <?php the_excerpt(); ?>
 154              </div><!-- .entry-summary -->
 155      <?php else : ?>
 156              <div class="entry-content">
 157                  <?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?>
 158                  <?php
 159                  wp_link_pages(
 160                      array(
 161                          'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ),
 162                          'after'  => '</div>',
 163                      )
 164                  );
 165                  ?>
 166              </div><!-- .entry-content -->
 167      <?php endif; ?>
 168  
 169              <div class="entry-utility">
 170                  <?php if ( count( get_the_category() ) ) : ?>
 171                      <span class="cat-links">
 172                          <?php
 173                          /* translators: 1: CSS classes, 2: Category list. */
 174                          printf( __( '<span class="%1$s">Posted in</span> %2$s', 'twentyten' ), 'entry-utility-prep entry-utility-prep-cat-links', get_the_category_list( ', ' ) );
 175                          ?>
 176                      </span>
 177                      <span class="meta-sep">|</span>
 178                  <?php endif; ?>
 179                  <?php
 180                      $tags_list = get_the_tag_list( '', ', ' );
 181                  if ( $tags_list ) :
 182                      ?>
 183                  <span class="tag-links">
 184                      <?php
 185                      /* translators: 1: CSS classes, 2: Category list. */
 186                      printf( __( '<span class="%1$s">Tagged</span> %2$s', 'twentyten' ), 'entry-utility-prep entry-utility-prep-tag-links', $tags_list );
 187                      ?>
 188                  </span>
 189                  <span class="meta-sep">|</span>
 190                  <?php endif; ?>
 191                  <span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'twentyten' ), __( '1 Comment', 'twentyten' ), __( '% Comments', 'twentyten' ) ); ?></span>
 192                  <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?>
 193              </div><!-- .entry-utility -->
 194          </div><!-- #post-<?php the_ID(); ?> -->
 195  
 196          <?php comments_template( '', true ); ?>
 197  
 198      <?php endif; // This was the if statement that broke the loop into three parts based on categories. ?>
 199  
 200  <?php endwhile; // End the loop. Whew. ?>
 201  
 202  <?php /* Display navigation to next/previous pages when applicable */ ?>
 203  <?php if ( $wp_query->max_num_pages > 1 ) : ?>
 204                  <div id="nav-below" class="navigation">
 205                      <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentyten' ) ); ?></div>
 206                      <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?></div>
 207                  </div><!-- #nav-below -->
 208  <?php endif; ?>


Generated: Wed Dec 11 01:00:03 2019 Cross-referenced by PHPXref 0.7.1