[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * The loop that displays an attachment
   4   *
   5   * The loop displays the posts and the post content. See
   6   * https://codex.wordpress.org/The_Loop to understand it and
   7   * https://codex.wordpress.org/Template_Tags to understand
   8   * the tags used in it.
   9   *
  10   * This can be overridden in child themes with loop-attachment.php.
  11   *
  12   * @package WordPress
  13   * @subpackage Twenty_Ten
  14   * @since Twenty Ten 1.2
  15   */
  16  ?>
  17  
  18  <?php
  19  if ( have_posts() ) {
  20      while ( have_posts() ) :
  21          the_post();
  22          ?>
  23  
  24                  <?php
  25                  if ( ! empty( $post->post_parent ) ) :
  26                      /* translators: %s: post title */
  27                      $post_tile = sprintf( __( 'Return to %s', 'twentyten' ), strip_tags( get_the_title( $post->post_parent ) ) );
  28                      ?>
  29                      <p class="page-title"><a href="<?php echo esc_url( get_permalink( $post->post_parent ) ); ?>" title="<?php echo esc_attr( $post_title ); ?>" rel="gallery">
  30                                                                  <?php
  31                                                                  /* translators: %s: title of parent post */
  32                                                                  printf( __( '<span class="meta-nav">&larr;</span> %s', 'twentyten' ), get_the_title( $post->post_parent ) );
  33                                                                  ?>
  34                      </a></p>
  35                  <?php endif; ?>
  36  
  37                      <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  38                      <h2 class="entry-title"><?php the_title(); ?></h2>
  39  
  40                      <div class="entry-meta">
  41                          <?php
  42                              printf(
  43                                  /* translators: %s: author display name */
  44                                  __( '<span class="%1$s">By</span> %2$s', 'twentyten' ),
  45                                  'meta-prep meta-prep-author',
  46                                  sprintf(
  47                                      '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
  48                                      get_author_posts_url( get_the_author_meta( 'ID' ) ),
  49                                      /* translators: %s: author display name */
  50                                      esc_attr( sprintf( __( 'View all posts by %s', 'twentyten' ), get_the_author() ) ),
  51                                      get_the_author()
  52                                  )
  53                              );
  54                          ?>
  55                              <span class="meta-sep">|</span>
  56                              <?php
  57                              printf(
  58                                  /* translators: 1: CSS classes: 2: date */
  59                                  __( '<span class="%1$s">Published</span> %2$s', 'twentyten' ),
  60                                  'meta-prep meta-prep-entry-date',
  61                                  sprintf(
  62                                      '<span class="entry-date"><abbr class="published" title="%1$s">%2$s</abbr></span>',
  63                                      esc_attr( get_the_time() ),
  64                                      get_the_date()
  65                                  )
  66                              );
  67                              if ( wp_attachment_is_image() ) {
  68                                  echo ' <span class="meta-sep">|</span> ';
  69                                  $metadata = wp_get_attachment_metadata();
  70                                  printf(
  71                                      /* translators: %s: image dimensions */
  72                                      __( 'Full size is %s pixels', 'twentyten' ),
  73                                      sprintf(
  74                                          '<a href="%1$s" title="%2$s">%3$s &times; %4$s</a>',
  75                                          esc_url( wp_get_attachment_url() ),
  76                                          esc_attr( __( 'Link to full-size image', 'twentyten' ) ),
  77                                          $metadata['width'],
  78                                          $metadata['height']
  79                                      )
  80                                  );
  81                              }
  82                              ?>
  83                              <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?>
  84                          </div><!-- .entry-meta -->
  85  
  86                          <div class="entry-content">
  87                          <div class="entry-attachment">
  88          <?php
  89          if ( wp_attachment_is_image() ) :
  90              $attachments = array_values(
  91                  get_children(
  92                      array(
  93                          'post_parent'    => $post->post_parent,
  94                          'post_status'    => 'inherit',
  95                          'post_type'      => 'attachment',
  96                          'post_mime_type' => 'image',
  97                          'order'          => 'ASC',
  98                          'orderby'        => 'menu_order ID',
  99                      )
 100                  )
 101              );
 102              foreach ( $attachments as $k => $attachment ) {
 103                  if ( $attachment->ID == $post->ID ) {
 104                      break;
 105                  }
 106              }
 107  
 108              // If there is more than 1 image attachment in a gallery
 109              if ( count( $attachments ) > 1 ) {
 110                  $k++;
 111                  if ( isset( $attachments[ $k ] ) ) {
 112                      // get the URL of the next image attachment
 113                      $next_attachment_url = get_attachment_link( $attachments[ $k ]->ID );
 114                  } else {          // or get the URL of the first image attachment
 115                      $next_attachment_url = get_attachment_link( $attachments[0]->ID );
 116                  }
 117              } else {
 118                  // or, if there's only 1 image attachment, get the URL of the image
 119                  $next_attachment_url = wp_get_attachment_url();
 120              }
 121              ?>
 122                          <p class="attachment"><a href="<?php echo esc_url( $next_attachment_url ); ?>" title="<?php the_title_attribute(); ?>" rel="attachment">
 123                                                                      <?php
 124                                                                      /**
 125                                                                       * Filter the Twenty Ten default attachment width.
 126                                                                       *
 127                                                                       * @since Twenty Ten 1.0
 128                                                                       *
 129                                                                       * @param int The default attachment width in pixels. Default 900.
 130                                                                       */
 131                                                                      $attachment_width = apply_filters( 'twentyten_attachment_size', 900 );
 132                                                                      /**
 133                                                                       * Filter the Twenty Ten default attachment height.
 134                                                                       *
 135                                                                       * @since Twenty Ten 1.0
 136                                                                       *
 137                                                                       * @param int The default attachment height in pixels. Default 900.
 138                                                                       */
 139                                                                      $attachment_height = apply_filters( 'twentyten_attachment_height', 900 );
 140                                                                      echo wp_get_attachment_image( $post->ID, array( $attachment_width, $attachment_height ) ); // filterable image width with, essentially, no limit for image height.
 141                                                                      ?>
 142                              </a></p>
 143  
 144                              <div id="nav-below" class="navigation">
 145                              <div class="nav-previous"><?php previous_image_link( false ); ?></div>
 146                              <div class="nav-next"><?php next_image_link( false ); ?></div>
 147                          </div><!-- #nav-below -->
 148          <?php else : ?>
 149                          <a href="<?php echo esc_url( wp_get_attachment_url() ); ?>" title="<?php the_title_attribute(); ?>" rel="attachment"><?php echo esc_html( wp_basename( get_permalink() ) ); ?></a>
 150      <?php endif; ?>
 151                          </div><!-- .entry-attachment -->
 152                          <div class="entry-caption">
 153                          <?php
 154                          if ( ! empty( $post->post_excerpt ) ) {
 155                              the_excerpt();}
 156                          ?>
 157  </div>
 158  
 159          <?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?>
 160          <?php
 161          wp_link_pages(
 162              array(
 163                  'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ),
 164                  'after'  => '</div>',
 165              )
 166          );
 167          ?>
 168  
 169                      </div><!-- .entry-content -->
 170  
 171                      <div class="entry-utility">
 172                          <?php twentyten_posted_in(); ?>
 173                          <?php edit_post_link( __( 'Edit', 'twentyten' ), ' <span class="edit-link">', '</span>' ); ?>
 174                      </div><!-- .entry-utility -->
 175                  </div><!-- #post-<?php the_ID(); ?> -->
 176  
 177          <?php comments_template(); ?>
 178  
 179  <?php endwhile;
 180  }; // end of the loop. ?>


Generated: Sun Jul 21 01:00:03 2019 Cross-referenced by PHPXref 0.7.1