PageRenderTime 45ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/toolbox/image.php

https://bitbucket.org/lgorence/quickpress
PHP | 110 lines | 79 code | 17 blank | 14 comment | 12 complexity | ad8408fb813cd1783fd04e9eae2e3d3c MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-1.0
  1. <?php
  2. /**
  3. * The template for displaying image attachments.
  4. *
  5. * @package Toolbox
  6. * @since Toolbox 0.1
  7. */
  8. get_header(); ?>
  9. <div id="primary" class="image-attachment">
  10. <div id="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"><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">%7$s</a>', 'toolbox' ),
  19. esc_attr( get_the_time() ),
  20. get_the_date(),
  21. wp_get_attachment_url(),
  22. $metadata['width'],
  23. $metadata['height'],
  24. get_permalink( $post->post_parent ),
  25. get_the_title( $post->post_parent )
  26. );
  27. ?>
  28. <?php edit_post_link( __( 'Edit', 'toolbox' ), '<span class="sep">|</span> <span class="edit-link">', '</span>' ); ?>
  29. </div><!-- .entry-meta -->
  30. <nav id="image-navigation">
  31. <span class="previous-image"><?php previous_image_link( false, __( '&larr; Previous' , 'toolbox' ) ); ?></span>
  32. <span class="next-image"><?php next_image_link( false, __( 'Next &rarr;' , 'toolbox' ) ); ?></span>
  33. </nav><!-- #image-navigation -->
  34. </header><!-- .entry-header -->
  35. <div class="entry-content">
  36. <div class="entry-attachment">
  37. <div class="attachment">
  38. <?php
  39. /**
  40. * 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,
  41. * 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
  42. */
  43. $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' ) ) );
  44. foreach ( $attachments as $k => $attachment ) {
  45. if ( $attachment->ID == $post->ID )
  46. break;
  47. }
  48. $k++;
  49. // If there is more than 1 attachment in a gallery
  50. if ( count( $attachments ) > 1 ) {
  51. if ( isset( $attachments[ $k ] ) )
  52. // get the URL of the next image attachment
  53. $next_attachment_url = get_attachment_link( $attachments[ $k ]->ID );
  54. else
  55. // or get the URL of the first image attachment
  56. $next_attachment_url = get_attachment_link( $attachments[ 0 ]->ID );
  57. } else {
  58. // or, if there's only 1 image, get the URL of the image
  59. $next_attachment_url = wp_get_attachment_url();
  60. }
  61. ?>
  62. <a href="<?php echo $next_attachment_url; ?>" title="<?php echo esc_attr( get_the_title() ); ?>" rel="attachment"><?php
  63. $attachment_size = apply_filters( 'toolbox_attachment_size', 1200 );
  64. echo wp_get_attachment_image( $post->ID, array( $attachment_size, $attachment_size ) ); // filterable image width with, essentially, no limit for image height.
  65. ?></a>
  66. </div><!-- .attachment -->
  67. <?php if ( ! empty( $post->post_excerpt ) ) : ?>
  68. <div class="entry-caption">
  69. <?php the_excerpt(); ?>
  70. </div>
  71. <?php endif; ?>
  72. </div><!-- .entry-attachment -->
  73. <?php the_content(); ?>
  74. <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'toolbox' ), 'after' => '</div>' ) ); ?>
  75. </div><!-- .entry-content -->
  76. <footer class="entry-meta">
  77. <?php if ( comments_open() && pings_open() ) : // Comments and trackbacks open ?>
  78. <?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>.', 'toolbox' ), get_trackback_url() ); ?>
  79. <?php elseif ( ! comments_open() && pings_open() ) : // Only trackbacks open ?>
  80. <?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>.', 'toolbox' ), get_trackback_url() ); ?>
  81. <?php elseif ( comments_open() && ! pings_open() ) : // Only comments open ?>
  82. <?php _e( 'Trackbacks are closed, but you can <a class="comment-link" href="#respond" title="Post a comment">post a comment</a>.', 'toolbox' ); ?>
  83. <?php elseif ( ! comments_open() && ! pings_open() ) : // Comments and trackbacks closed ?>
  84. <?php _e( 'Both comments and trackbacks are currently closed.', 'toolbox' ); ?>
  85. <?php endif; ?>
  86. <?php edit_post_link( __( 'Edit', 'toolbox' ), ' <span class="edit-link">', '</span>' ); ?>
  87. </footer><!-- .entry-meta -->
  88. </article><!-- #post-<?php the_ID(); ?> -->
  89. <?php comments_template(); ?>
  90. <?php endwhile; // end of the loop. ?>
  91. </div><!-- #content -->
  92. </div><!-- #primary -->
  93. <?php get_footer(); ?>