/wp-content/themes/twentyten/loop-attachment.php

https://github.com/livinglab/openlab · PHP · 182 lines · 131 code · 12 blank · 39 comment · 13 complexity · 63b92b404c90eee791439d591668dd07 MD5 · raw file

  1. <?php
  2. /**
  3. * The loop that displays an attachment
  4. *
  5. * The loop displays the posts and the post content. See
  6. * https://developer.wordpress.org/themes/basics/the-loop/ to understand it and
  7. * https://developer.wordpress.org/themes/basics/template-tags/ to understand
  8. * the tags used in it.
  9. *
  10. * This can be overridden in child themes with loop-attachment.php.
  11. *
  12. * @package WordPress
  13. * @subpackage Twenty_Ten
  14. * @since Twenty Ten 1.2
  15. */
  16. ?>
  17. <?php
  18. if ( have_posts() ) {
  19. while ( have_posts() ) :
  20. the_post();
  21. ?>
  22. <?php
  23. if ( ! empty( $post->post_parent ) ) :
  24. /* translators: %s: Post title. */
  25. $post_title = sprintf( __( 'Go to %s', 'twentyten' ), strip_tags( get_the_title( $post->post_parent ) ) );
  26. ?>
  27. <p class="page-title"><a href="<?php echo esc_url( get_permalink( $post->post_parent ) ); ?>" title="<?php echo esc_attr( $post_title ); ?>" rel="gallery">
  28. <?php
  29. /* translators: %s: Title of parent post. */
  30. printf( __( '<span class="meta-nav">&larr;</span> %s', 'twentyten' ), get_the_title( $post->post_parent ) );
  31. ?>
  32. </a></p>
  33. <?php endif; ?>
  34. <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  35. <h2 class="entry-title"><?php the_title(); ?></h2>
  36. <div class="entry-meta">
  37. <?php
  38. printf(
  39. /* translators: %s: Author display name. */
  40. __( '<span class="%1$s">By</span> %2$s', 'twentyten' ),
  41. 'meta-prep meta-prep-author',
  42. sprintf(
  43. '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
  44. get_author_posts_url( get_the_author_meta( 'ID' ) ),
  45. /* translators: %s: Author display name. */
  46. esc_attr( sprintf( __( 'View all posts by %s', 'twentyten' ), get_the_author() ) ),
  47. get_the_author()
  48. )
  49. );
  50. ?>
  51. <span class="meta-sep">|</span>
  52. <?php
  53. printf(
  54. /* translators: 1: CSS classes, 2: Date. */
  55. __( '<span class="%1$s">Published</span> %2$s', 'twentyten' ),
  56. 'meta-prep meta-prep-entry-date',
  57. sprintf(
  58. '<span class="entry-date"><abbr class="published" title="%1$s">%2$s</abbr></span>',
  59. esc_attr( get_the_time() ),
  60. get_the_date()
  61. )
  62. );
  63. if ( wp_attachment_is_image() ) {
  64. echo ' <span class="meta-sep">|</span> ';
  65. $metadata = wp_get_attachment_metadata();
  66. printf(
  67. /* translators: %s: Image dimensions. */
  68. __( 'Full size is %s pixels', 'twentyten' ),
  69. sprintf(
  70. '<a href="%1$s" title="%2$s">%3$s &times; %4$s</a>',
  71. esc_url( wp_get_attachment_url() ),
  72. esc_attr( __( 'Link to full-size image', 'twentyten' ) ),
  73. $metadata['width'],
  74. $metadata['height']
  75. )
  76. );
  77. }
  78. ?>
  79. <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?>
  80. </div><!-- .entry-meta -->
  81. <div class="entry-content">
  82. <div class="entry-attachment">
  83. <?php
  84. if ( wp_attachment_is_image() ) :
  85. $attachments = array_values(
  86. get_children(
  87. array(
  88. 'post_parent' => $post->post_parent,
  89. 'post_status' => 'inherit',
  90. 'post_type' => 'attachment',
  91. 'post_mime_type' => 'image',
  92. 'order' => 'ASC',
  93. 'orderby' => 'menu_order ID',
  94. )
  95. )
  96. );
  97. foreach ( $attachments as $k => $attachment ) {
  98. if ( $attachment->ID == $post->ID ) {
  99. break;
  100. }
  101. }
  102. // If there is more than 1 image attachment in a gallery...
  103. if ( count( $attachments ) > 1 ) {
  104. $k++;
  105. if ( isset( $attachments[ $k ] ) ) {
  106. // ...get the URL of the next image attachment.
  107. $next_attachment_url = get_attachment_link( $attachments[ $k ]->ID );
  108. } else {
  109. // ...or get the URL of the first image attachment.
  110. $next_attachment_url = get_attachment_link( $attachments[0]->ID );
  111. }
  112. } else {
  113. // Or, if there's only 1 image attachment, get the URL of the image.
  114. $next_attachment_url = wp_get_attachment_url();
  115. }
  116. ?>
  117. <p class="attachment"><a href="<?php echo esc_url( $next_attachment_url ); ?>" title="<?php the_title_attribute(); ?>" rel="attachment">
  118. <?php
  119. /**
  120. * Filters the Twenty Ten default attachment width.
  121. *
  122. * @since Twenty Ten 1.0
  123. *
  124. * @param int The default attachment width in pixels. Default 900.
  125. */
  126. $attachment_width = apply_filters( 'twentyten_attachment_size', 900 );
  127. /**
  128. * Filters the Twenty Ten default attachment height.
  129. *
  130. * @since Twenty Ten 1.0
  131. *
  132. * @param int The default attachment height in pixels. Default 900.
  133. */
  134. $attachment_height = apply_filters( 'twentyten_attachment_height', 900 );
  135. // Filterable image width with, essentially, no limit for image height.
  136. echo wp_get_attachment_image( $post->ID, array( $attachment_width, $attachment_height ) );
  137. ?>
  138. </a></p>
  139. <div id="nav-below" class="navigation">
  140. <div class="nav-previous"><?php previous_image_link( false ); ?></div>
  141. <div class="nav-next"><?php next_image_link( false ); ?></div>
  142. </div><!-- #nav-below -->
  143. <?php else : ?>
  144. <a href="<?php echo esc_url( wp_get_attachment_url() ); ?>" title="<?php the_title_attribute(); ?>" rel="attachment"><?php echo esc_html( wp_basename( get_permalink() ) ); ?></a>
  145. <?php endif; ?>
  146. </div><!-- .entry-attachment -->
  147. <div class="entry-caption">
  148. <?php
  149. if ( ! empty( $post->post_excerpt ) ) {
  150. the_excerpt();}
  151. ?>
  152. </div>
  153. <?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?>
  154. <?php
  155. wp_link_pages(
  156. array(
  157. 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ),
  158. 'after' => '</div>',
  159. )
  160. );
  161. ?>
  162. </div><!-- .entry-content -->
  163. <div class="entry-utility">
  164. <?php twentyten_posted_in(); ?>
  165. <?php edit_post_link( __( 'Edit', 'twentyten' ), ' <span class="edit-link">', '</span>' ); ?>
  166. </div><!-- .entry-utility -->
  167. </div><!-- #post-<?php the_ID(); ?> -->
  168. <?php comments_template(); ?>
  169. <?php endwhile;
  170. }; // End of the loop. ?>