PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/abnopanda/wordpress
PHP | 106 lines | 71 code | 18 blank | 17 comment | 8 complexity | ee7de97e6d917d76ec8809476e6822dc MD5 | raw file
  1. <?php
  2. /**
  3. * The template for displaying image attachments.
  4. *
  5. * Learn more: http://codex.wordpress.org/Template_Hierarchy
  6. *
  7. * @package WordPress
  8. * @subpackage Twenty_Twelve
  9. * @since Twenty Twelve 1.0
  10. */
  11. get_header(); ?>
  12. <div id="primary" class="site-content">
  13. <div id="content" role="main">
  14. <?php while ( have_posts() ) : the_post(); ?>
  15. <article id="post-<?php the_ID(); ?>" <?php post_class( 'image-attachment' ); ?>>
  16. <header class="entry-header">
  17. <h1 class="entry-title"><?php the_title(); ?></h1>
  18. <footer class="entry-meta">
  19. <?php
  20. $metadata = wp_get_attachment_metadata();
  21. printf( __( '<span class="meta-prep meta-prep-entry-date">Published </span> <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>.', 'twentytwelve' ),
  22. esc_attr( get_the_date( 'c' ) ),
  23. esc_html( get_the_date() ),
  24. esc_url( wp_get_attachment_url() ),
  25. $metadata['width'],
  26. $metadata['height'],
  27. esc_url( get_permalink( $post->post_parent ) ),
  28. esc_attr( strip_tags( get_the_title( $post->post_parent ) ) ),
  29. get_the_title( $post->post_parent )
  30. );
  31. ?>
  32. <?php edit_post_link( __( 'Edit', 'twentytwelve' ), '<span class="edit-link">', '</span>' ); ?>
  33. </footer><!-- .entry-meta -->
  34. <nav id="image-navigation" class="navigation" role="navigation">
  35. <span class="previous-image"><?php previous_image_link( false, __( '&larr; Previous', 'twentytwelve' ) ); ?></span>
  36. <span class="next-image"><?php next_image_link( false, __( 'Next &rarr;', 'twentytwelve' ) ); ?></span>
  37. </nav><!-- #image-navigation -->
  38. </header><!-- .entry-header -->
  39. <div class="entry-content">
  40. <div class="entry-attachment">
  41. <div class="attachment">
  42. <?php
  43. /**
  44. * 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,
  45. * 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
  46. */
  47. $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' ) ) );
  48. foreach ( $attachments as $k => $attachment ) :
  49. if ( $attachment->ID == $post->ID )
  50. break;
  51. endforeach;
  52. $k++;
  53. // If there is more than 1 attachment in a gallery
  54. if ( count( $attachments ) > 1 ) :
  55. if ( isset( $attachments[ $k ] ) ) :
  56. // get the URL of the next image attachment
  57. $next_attachment_url = get_attachment_link( $attachments[ $k ]->ID );
  58. else :
  59. // or get the URL of the first image attachment
  60. $next_attachment_url = get_attachment_link( $attachments[ 0 ]->ID );
  61. endif;
  62. else :
  63. // or, if there's only 1 image, get the URL of the image
  64. $next_attachment_url = wp_get_attachment_url();
  65. endif;
  66. ?>
  67. <a href="<?php echo esc_url( $next_attachment_url ); ?>" title="<?php the_title_attribute(); ?>" rel="attachment"><?php
  68. $attachment_size = apply_filters( 'twentytwelve_attachment_size', array( 960, 960 ) );
  69. echo wp_get_attachment_image( $post->ID, $attachment_size );
  70. ?></a>
  71. <?php if ( ! empty( $post->post_excerpt ) ) : ?>
  72. <div class="entry-caption">
  73. <?php the_excerpt(); ?>
  74. </div>
  75. <?php endif; ?>
  76. </div><!-- .attachment -->
  77. </div><!-- .entry-attachment -->
  78. <div class="entry-description">
  79. <?php the_content(); ?>
  80. <?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'twentytwelve' ), 'after' => '</div>' ) ); ?>
  81. </div><!-- .entry-description -->
  82. </div><!-- .entry-content -->
  83. </article><!-- #post -->
  84. <?php comments_template(); ?>
  85. <?php endwhile; // end of the loop. ?>
  86. </div><!-- #content -->
  87. </div><!-- #primary -->
  88. <?php get_footer(); ?>