[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-content/themes/twentyeleven/ -> image.php (source)

   1  <?php
   2  /**
   3   * Template for displaying image attachments
   4   *
   5   * @package WordPress
   6   * @subpackage Twenty_Eleven
   7   * @since Twenty Eleven 1.0
   8   */
   9  
  10  get_header(); ?>
  11  
  12          <div id="primary" class="image-attachment">
  13              <div id="content" role="main">
  14  
  15              <?php
  16              while ( have_posts() ) :
  17                  the_post();
  18                  ?>
  19  
  20                  <nav id="nav-single">
  21                      <h3 class="assistive-text"><?php _e( 'Image navigation', 'twentyeleven' ); ?></h3>
  22                      <span class="nav-previous"><?php previous_image_link( false, __( '&larr; Previous', 'twentyeleven' ) ); ?></span>
  23                      <span class="nav-next"><?php next_image_link( false, __( 'Next &rarr;', 'twentyeleven' ) ); ?></span>
  24                  </nav><!-- #nav-single -->
  25  
  26                      <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  27                          <header class="entry-header">
  28                              <h1 class="entry-title"><?php the_title(); ?></h1>
  29  
  30                              <div class="entry-meta">
  31                                  <?php
  32                                      $metadata = wp_get_attachment_metadata();
  33                                      printf(
  34                                          /* translators: 1: Time, 2: Date, 3: Image permalink, 4: Image width, 5: Image height, 6: Parent permalink, 7: Parent post title, 8: Parent post title. */
  35                                          __( '<span class="meta-prep meta-prep-entry-date">Published </span> <span class="entry-date"><abbr class="published" title="%1$s">%2$s</abbr></span> at <a href="%3$s" title="Link to full-size image">%4$s &times; %5$s</a> in <a href="%6$s" title="Return to %7$s" rel="gallery">%8$s</a>', 'twentyeleven' ),
  36                                          esc_attr( get_the_time() ),
  37                                          get_the_date(),
  38                                          esc_url( wp_get_attachment_url() ),
  39                                          $metadata['width'],
  40                                          $metadata['height'],
  41                                          esc_url( get_permalink( $post->post_parent ) ),
  42                                          esc_attr( strip_tags( get_the_title( $post->post_parent ) ) ),
  43                                          get_the_title( $post->post_parent )
  44                                      );
  45                                  ?>
  46                                  <?php edit_post_link( __( 'Edit', 'twentyeleven' ), '<span class="edit-link">', '</span>' ); ?>
  47                              </div><!-- .entry-meta -->
  48  
  49                          </header><!-- .entry-header -->
  50  
  51                          <div class="entry-content">
  52  
  53                              <div class="entry-attachment">
  54                                  <div class="attachment">
  55                  <?php
  56                  /*
  57                  * Grab the IDs of all the image attachments in a gallery so we can get the URL of the next adjacent image in a gallery,
  58                  * or the first image (if we're looking at the last image in a gallery), or, in a gallery of one, just the link to that image file
  59                  */
  60                  $attachments = array_values(
  61                      get_children(
  62                          array(
  63                              'post_parent'    => $post->post_parent,
  64                              'post_status'    => 'inherit',
  65                              'post_type'      => 'attachment',
  66                              'post_mime_type' => 'image',
  67                              'order'          => 'ASC',
  68                              'orderby'        => 'menu_order ID',
  69                          )
  70                      )
  71                  );
  72                  foreach ( $attachments as $k => $attachment ) {
  73                      if ( $attachment->ID == $post->ID ) {
  74                          break;
  75                      }
  76                  }
  77  
  78                  // If there is more than 1 attachment in a gallery
  79                  if ( count( $attachments ) > 1 ) {
  80                      $k++;
  81                      if ( isset( $attachments[ $k ] ) ) {
  82                          // get the URL of the next image attachment
  83                          $next_attachment_url = get_attachment_link( $attachments[ $k ]->ID );
  84                      } else {      // or get the URL of the first image attachment
  85                          $next_attachment_url = get_attachment_link( $attachments[0]->ID );
  86                      }
  87                  } else {
  88                      // or, if there's only 1 image, get the URL of the image
  89                      $next_attachment_url = wp_get_attachment_url();
  90                  }
  91                  ?>
  92                                      <a href="<?php echo esc_url( $next_attachment_url ); ?>" title="<?php the_title_attribute(); ?>" rel="attachment">
  93                                                          <?php
  94                                                          /**
  95                                                           * Filter the Twenty Eleven default attachment size.
  96                                                           *
  97                                                           * @since Twenty Eleven 1.0
  98                                                           *
  99                                                           * @param int The height and width attachment size dimensions in pixels. Default 848.
 100                                                           */
 101                                                          $attachment_size = apply_filters( 'twentyeleven_attachment_size', 848 );
 102                                                          echo wp_get_attachment_image( $post->ID, array( $attachment_size, 1024 ) ); // filterable image width with 1024px limit for image height.
 103                                                          ?>
 104                                      </a>
 105  
 106                                      <?php if ( ! empty( $post->post_excerpt ) ) : ?>
 107                                      <div class="entry-caption">
 108                                          <?php the_excerpt(); ?>
 109                                      </div>
 110                                      <?php endif; ?>
 111                                  </div><!-- .attachment -->
 112  
 113                              </div><!-- .entry-attachment -->
 114  
 115                              <div class="entry-description">
 116                                  <?php the_content(); ?>
 117                                  <?php
 118                                  wp_link_pages(
 119                                      array(
 120                                          'before' => '<div class="page-link"><span>' . __( 'Pages:', 'twentyeleven' ) . '</span>',
 121                                          'after'  => '</div>',
 122                                      )
 123                                  );
 124                                  ?>
 125                              </div><!-- .entry-description -->
 126  
 127                          </div><!-- .entry-content -->
 128  
 129                      </article><!-- #post-<?php the_ID(); ?> -->
 130  
 131                      <?php comments_template(); ?>
 132  
 133                  <?php endwhile; // end of the loop. ?>
 134  
 135              </div><!-- #content -->
 136          </div><!-- #primary -->
 137  
 138  <?php get_footer(); ?>


Generated: Mon Oct 21 01:00:03 2019 Cross-referenced by PHPXref 0.7.1