image.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * The template for displaying image attachments.
  4. *
  5. * @package _s
  6. * @since _s 1.0
  7. */
  8. get_header();
  9. ?>
  10. <div id="primary" class="site-content image-attachment">
  11. <div id="content" role="main">
  12. <?php while ( have_posts() ) : the_post(); ?>
  13. <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  14. <header class="entry-header">
  15. <h1 class="entry-title"><?php the_title(); ?></h1>
  16. <div class="entry-meta">
  17. <?php
  18. $metadata = wp_get_attachment_metadata();
  19. printf( __( 'Published <span class="entry-date"><time class="entry-date" datetime="%1$s" pubdate>%2$s</time></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">%7$s</a>', '_s' ),
  20. esc_attr( get_the_date( 'c' ) ),
  21. esc_html( get_the_date() ),
  22. wp_get_attachment_url(),
  23. $metadata['width'],
  24. $metadata['height'],
  25. get_permalink( $post->post_parent ),
  26. get_the_title( $post->post_parent )
  27. );
  28. ?>
  29. <?php edit_post_link( __( 'Edit', '_s' ), '<span class="sep">|</span> <span class="edit-link">', '</span>' ); ?>
  30. </div><!-- .entry-meta -->
  31. <nav id="image-navigation">
  32. <span class="previous-image"><?php previous_image_link( false, __( '&larr; Previous', '_s' ) ); ?></span>
  33. <span class="next-image"><?php next_image_link( false, __( 'Next &rarr;', '_s' ) ); ?></span>
  34. </nav><!-- #image-navigation -->
  35. </header><!-- .entry-header -->
  36. <div class="entry-content">
  37. <div class="entry-attachment">
  38. <div class="attachment">
  39. <?php
  40. /**
  41. * 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,
  42. * 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
  43. */
  44. $attachments = array_values( get_children( array( 'post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID' ) ) );
  45. foreach ( $attachments as $k => $attachment ) {
  46. if ( $attachment->ID == $post->ID )
  47. break;
  48. }
  49. $k++;
  50. // If there is more than 1 attachment in a gallery
  51. if ( count( $attachments ) > 1 ) {
  52. if ( isset( $attachments[ $k ] ) )
  53. // get the URL of the next image attachment
  54. $next_attachment_url = get_attachment_link( $attachments[ $k ]->ID );
  55. else
  56. // or get the URL of the first image attachment
  57. $next_attachment_url = get_attachment_link( $attachments[ 0 ]->ID );
  58. } else {
  59. // or, if there's only 1 image, get the URL of the image
  60. $next_attachment_url = wp_get_attachment_url();
  61. }
  62. ?>
  63. <a href="<?php echo $next_attachment_url; ?>" title="<?php echo esc_attr( get_the_title() ); ?>" rel="attachment"><?php
  64. $attachment_size = apply_filters( '_s_attachment_size', 1200 );
  65. echo wp_get_attachment_image( $post->ID, array( $attachment_size, $attachment_size ) ); // filterable image width with, essentially, no limit for image height.
  66. ?></a>
  67. </div><!-- .attachment -->
  68. <?php if ( ! empty( $post->post_excerpt ) ) : ?>
  69. <div class="entry-caption">
  70. <?php the_excerpt(); ?>
  71. </div>
  72. <?php endif; ?>
  73. </div><!-- .entry-attachment -->
  74. <?php the_content(); ?>
  75. <?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', '_s' ), 'after' => '</div>' ) ); ?>
  76. </div><!-- .entry-content -->
  77. <footer class="entry-meta">
  78. <?php if ( comments_open() && pings_open() ) : // Comments and trackbacks open ?>
  79. <?php printf( __( '<a class="comment-link" href="#respond" title="Post a comment">Post a comment</a> or leave a trackback: <a class="trackback-link" href="%s" title="Trackback URL for your post" rel="trackback">Trackback URL</a>.', '_s' ), get_trackback_url() ); ?>
  80. <?php elseif ( ! comments_open() && pings_open() ) : // Only trackbacks open ?>
  81. <?php printf( __( 'Comments are closed, but you can leave a trackback: <a class="trackback-link" href="%s" title="Trackback URL for your post" rel="trackback">Trackback URL</a>.', '_s' ), get_trackback_url() ); ?>
  82. <?php elseif ( comments_open() && ! pings_open() ) : // Only comments open ?>
  83. <?php _e( 'Trackbacks are closed, but you can <a class="comment-link" href="#respond" title="Post a comment">post a comment</a>.', '_s' ); ?>
  84. <?php elseif ( ! comments_open() && ! pings_open() ) : // Comments and trackbacks closed ?>
  85. <?php _e( 'Both comments and trackbacks are currently closed.', '_s' ); ?>
  86. <?php endif; ?>
  87. <?php edit_post_link( __( 'Edit', '_s' ), ' <span class="edit-link">', '</span>' ); ?>
  88. </footer><!-- .entry-meta -->
  89. </article><!-- #post-<?php the_ID(); ?> -->
  90. <?php comments_template(); ?>
  91. <?php endwhile; // end of the loop. ?>
  92. </div><!-- #content -->
  93. </div><!-- #primary .site-content -->
  94. <?php get_footer(); ?>