image.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * The template for displaying image attachments.
  4. *
  5. * @package Spun
  6. */
  7. get_header();
  8. ?>
  9. <div id="primary" class="content-area image-attachment">
  10. <div id="content" class="site-content" role="main">
  11. <?php while ( have_posts() ) : the_post(); ?>
  12. <nav id="image-navigation" class="site-navigation">
  13. <span class="previous-image nav-previous"><?php previous_image_link( false, __( '<span class="meta-nav">&laquo;</span>', 'spun' ) ); ?></span>
  14. <span class="next-image nav-next"><?php next_image_link( false, __( '<span class="meta-nav">&raquo;</span>', 'spun' ) ); ?></span>
  15. </nav><!-- #image-navigation -->
  16. <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  17. <header class="entry-header">
  18. <h1 class="entry-title"><?php the_title(); ?></h1>
  19. </header><!-- .entry-header -->
  20. <div class="entry-content">
  21. <div class="entry-attachment">
  22. <div class="attachment">
  23. <?php
  24. /**
  25. * 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,
  26. * 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
  27. */
  28. $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' ) ) );
  29. foreach ( $attachments as $k => $attachment ) {
  30. if ( $attachment->ID == $post->ID )
  31. break;
  32. }
  33. $k++;
  34. // If there is more than 1 attachment in a gallery
  35. if ( count( $attachments ) > 1 ) {
  36. if ( isset( $attachments[ $k ] ) )
  37. // get the URL of the next image attachment
  38. $next_attachment_url = get_attachment_link( $attachments[ $k ]->ID );
  39. else
  40. // or get the URL of the first image attachment
  41. $next_attachment_url = get_attachment_link( $attachments[ 0 ]->ID );
  42. } else {
  43. // or, if there's only 1 image, get the URL of the image
  44. $next_attachment_url = wp_get_attachment_url();
  45. }
  46. ?>
  47. <a href="<?php echo esc_url( $next_attachment_url ); ?>" title="<?php echo esc_attr( get_the_title() ); ?>" rel="attachment"><?php
  48. $attachment_size = apply_filters( 'spun_attachment_size', array( 1200, 1200 ) ); // Filterable image size.
  49. echo wp_get_attachment_image( $post->ID, $attachment_size );
  50. ?></a>
  51. </div><!-- .attachment -->
  52. <?php if ( ! empty( $post->post_excerpt ) ) : ?>
  53. <div class="entry-caption">
  54. <?php the_excerpt(); ?>
  55. </div><!-- .entry-caption -->
  56. <?php endif; ?>
  57. </div><!-- .entry-attachment -->
  58. <?php the_content(); ?>
  59. <?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'spun' ), 'after' => '</div>' ) ); ?>
  60. </div><!-- .entry-content -->
  61. <footer class="entry-meta">
  62. <?php if ( ! post_password_required() && ( comments_open() || '0' != get_comments_number() ) ) : ?>
  63. <span class="comments-link">
  64. <a href="#comments-toggle">
  65. <span class="tail"></span>
  66. <?php echo comments_number( __( '+', 'spun' ), __( '1', 'spun' ), __( '%', 'spun' ) ); ?>
  67. </a>
  68. </span>
  69. <?php endif; ?>
  70. <?php
  71. $metadata = wp_get_attachment_metadata();
  72. printf( __( '<span class="entry-date"><time class="entry-date" datetime="%1$s" pubdate>%2$s</time></span><br /><a href="%3$s" title="Link to full-size image">%4$s &times; %5$s</a><br /><a href="%6$s" title="Return to %7$s" rel="gallery">%7$s</a>', 'spun' ),
  73. esc_attr( get_the_date( 'c' ) ),
  74. esc_html( get_the_date() ),
  75. wp_get_attachment_url(),
  76. $metadata['width'],
  77. $metadata['height'],
  78. get_permalink( $post->post_parent ),
  79. get_the_title( $post->post_parent )
  80. );
  81. ?>
  82. <?php edit_post_link( __( 'Edit', 'spun' ), '<br /><span class="edit-link">', '</span>' ); ?>
  83. </footer><!-- .entry-meta -->
  84. </article><!-- #post-<?php the_ID(); ?> -->
  85. <?php comments_template(); ?>
  86. <?php endwhile; // end of the loop. ?>
  87. </div><!-- #content .site-content -->
  88. </div><!-- #primary .content-area .image-attachment -->
  89. <?php get_footer(); ?>