/image.php

https://bitbucket.org/odddogmedia/_s · PHP · 127 lines · 96 code · 17 blank · 14 comment · 15 complexity · 19c0eda88473fae1d9c3c11b139a617f MD5 · raw file

  1. <?php
  2. /**
  3. * The template for displaying image attachments.
  4. *
  5. * @package _s
  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. <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  13. <header class="entry-header">
  14. <h1 class="entry-title"><?php the_title(); ?></h1>
  15. <div class="entry-meta">
  16. <?php
  17. $metadata = wp_get_attachment_metadata();
  18. printf( __( 'Published <span class="entry-date"><time class="entry-date" datetime="%1$s">%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">%8$s</a>', '_s' ),
  19. esc_attr( get_the_date( 'c' ) ),
  20. esc_html( get_the_date() ),
  21. wp_get_attachment_url(),
  22. $metadata['width'],
  23. $metadata['height'],
  24. get_permalink( $post->post_parent ),
  25. esc_attr( strip_tags( get_the_title( $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 role="navigation" id="image-navigation" class="navigation-image">
  32. <div class="nav-previous"><?php previous_image_link( false, __( '<span class="meta-nav">&larr;</span> Previous', '_s' ) ); ?></div>
  33. <div class="nav-next"><?php next_image_link( false, __( 'Next <span class="meta-nav">&rarr;</span>', '_s' ) ); ?></div>
  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(
  45. 'post_parent' => $post->post_parent,
  46. 'post_status' => 'inherit',
  47. 'post_type' => 'attachment',
  48. 'post_mime_type' => 'image',
  49. 'order' => 'ASC',
  50. 'orderby' => 'menu_order ID'
  51. ) ) );
  52. foreach ( $attachments as $k => $attachment ) {
  53. if ( $attachment->ID == $post->ID )
  54. break;
  55. }
  56. $k++;
  57. // If there is more than 1 attachment in a gallery
  58. if ( count( $attachments ) > 1 ) {
  59. if ( isset( $attachments[ $k ] ) )
  60. // get the URL of the next image attachment
  61. $next_attachment_url = get_attachment_link( $attachments[ $k ]->ID );
  62. else
  63. // or get the URL of the first image attachment
  64. $next_attachment_url = get_attachment_link( $attachments[ 0 ]->ID );
  65. } else {
  66. // or, if there's only 1 image, get the URL of the image
  67. $next_attachment_url = wp_get_attachment_url();
  68. }
  69. ?>
  70. <a href="<?php echo esc_url( $next_attachment_url ); ?>" title="<?php the_title_attribute(); ?>" rel="attachment"><?php
  71. $attachment_size = apply_filters( '_s_attachment_size', array( 1200, 1200 ) ); // Filterable image size.
  72. echo wp_get_attachment_image( get_the_ID(), $attachment_size );
  73. ?></a>
  74. </div><!-- .attachment -->
  75. <?php if ( has_excerpt() ) : ?>
  76. <div class="entry-caption">
  77. <?php the_excerpt(); ?>
  78. </div><!-- .entry-caption -->
  79. <?php endif; ?>
  80. </div><!-- .entry-attachment -->
  81. <?php the_content(); ?>
  82. <?php
  83. wp_link_pages( array(
  84. 'before' => '<div class="page-links">' . __( 'Pages:', '_s' ),
  85. 'after' => '</div>',
  86. ) );
  87. ?>
  88. </div><!-- .entry-content -->
  89. <footer class="entry-meta">
  90. <?php if ( comments_open() && pings_open() ) : // Comments and trackbacks open ?>
  91. <?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() ); ?>
  92. <?php elseif ( ! comments_open() && pings_open() ) : // Only trackbacks open ?>
  93. <?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() ); ?>
  94. <?php elseif ( comments_open() && ! pings_open() ) : // Only comments open ?>
  95. <?php _e( 'Trackbacks are closed, but you can <a class="comment-link" href="#respond" title="Post a comment">post a comment</a>.', '_s' ); ?>
  96. <?php elseif ( ! comments_open() && ! pings_open() ) : // Comments and trackbacks closed ?>
  97. <?php _e( 'Both comments and trackbacks are currently closed.', '_s' ); ?>
  98. <?php endif; ?>
  99. <?php edit_post_link( __( 'Edit', '_s' ), ' <span class="edit-link">', '</span>' ); ?>
  100. </footer><!-- .entry-meta -->
  101. </article><!-- #post-<?php the_ID(); ?> -->
  102. <?php
  103. // If comments are open or we have at least one comment, load up the comment template
  104. if ( comments_open() || '0' != get_comments_number() )
  105. comments_template();
  106. ?>
  107. <?php endwhile; // end of the loop. ?>
  108. </div><!-- #content -->
  109. </div><!-- #primary -->
  110. <?php get_footer(); ?>