image.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * The template for displaying image attachments.
  4. *
  5. * @package Libretto
  6. */
  7. get_header();
  8. /**
  9. * Set the content width if it hasn't already been determined
  10. */
  11. if ( ! isset( $content_width ) ) {
  12. $content_width = 720; /* 680px wide plus a 40px buffer */
  13. }
  14. ?>
  15. <div id="primary" class="content-area image-attachment">
  16. <div id="content" class="site-content" role="main">
  17. <?php while ( have_posts() ) : the_post(); ?>
  18. <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  19. <div class="entry-content">
  20. <?php
  21. // We're going to use our custom "oversized" image size here
  22. $attachment_size = apply_filters( 'libretto_attachment_size', 'libretto-oversized' );
  23. $attachment_meta = wp_get_attachment_metadata( $post->ID );
  24. if ( $attachment_meta['width'] > 890 ) {
  25. $class = 'libretto-oversized';
  26. } else {
  27. $class = 'aligncenter';
  28. }
  29. // Output the actual image
  30. echo wp_get_attachment_image( get_the_ID(), $attachment_size, false, array( 'class' => $class ) );
  31. ?>
  32. <?php if ( has_excerpt() ) : ?>
  33. <div class="entry-caption">
  34. <?php the_excerpt(); ?>
  35. </div><!-- .entry-caption -->
  36. <?php endif; ?>
  37. <?php // Add prev/next navigation. TODO: improve this so it matches with look & feel of navs in other places ?>
  38. <?php if ( $post->post_parent ) { ?>
  39. <nav id="nav-below" class="navigation-image" role="navigation">
  40. <div class="previous">
  41. <?php previous_image_link( false, '<span class="meta-nav">' . __( 'Previous image', 'libretto' ) . '</span>' ); ?>
  42. </div><!-- .previous -->
  43. <div class="next">
  44. <?php next_image_link( false, '<span class="meta-nav">' . __( 'Next image', 'libretto' ) . '</span>' ); ?>
  45. </div><!-- .next -->
  46. </nav><!-- .navigation-image -->
  47. <?php } ?>
  48. <?php
  49. the_content();
  50. wp_link_pages( array(
  51. 'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'libretto' ) . '</span>',
  52. 'after' => '</div>',
  53. 'link_before' => '<span>',
  54. 'link_after' => '</span>',
  55. 'pagelink' => '<span class="screen-reader-text">' . __( 'Page', 'libretto' ) . ' </span>%',
  56. 'separator' => '<span class="screen-reader-text">, </span>',
  57. ) );
  58. ?>
  59. </div><!-- .entry-content -->
  60. <footer class="entry-meta">
  61. <?php edit_post_link( __( 'Edit', 'libretto' ), '<span class="edit-link">', '</span>' ); ?>
  62. </footer><!-- .entry-footer -->
  63. </article><!-- #post-## -->
  64. <?php
  65. // If comments are open or we have at least one comment, load up the comment template
  66. if ( comments_open() || get_comments_number() ) :
  67. comments_template();
  68. endif;
  69. // End the loop.
  70. endwhile;
  71. ?>
  72. </main><!-- .site-main -->
  73. </div><!-- .content-area -->
  74. <?php get_footer(); ?>