Advertisement
specht

loop attachment

Mar 8th, 2011
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.12 KB | None | 0 0
  1. <?php
  2. /**
  3. * The loop that displays an attachment.
  4. *
  5. * The loop displays the posts and the post content. See
  6. * http://codex.wordpress.org/The_Loop to understand it and
  7. * http://codex.wordpress.org/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.  
  18. <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
  19.  
  20. <?php if ( ! empty( $post->post_parent ) ) : ?>
  21. <p class="page-title"><a href="<?php echo get_permalink( $post->post_parent ); ?>" title="<?php esc_attr( printf( __( 'Return to %s', 'twentyten' ), get_the_title( $post->post_parent ) ) ); ?>" rel="gallery"><?php
  22. /* translators: %s - title of parent post */
  23. printf( __( '<span class="meta-nav">&larr;</span> %s', 'twentyten' ), get_the_title( $post->post_parent ) );
  24. ?></a></p>
  25. <?php endif; ?>
  26.  
  27. <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  28. <h2 class="entry-title"><?php the_title(); ?></h2>
  29.  
  30.  
  31.  
  32. <div class="entry-meta">
  33. <?php
  34. printf( __( '<span class="%1$s">By</span> %2$s', 'twentyten' ),
  35. 'meta-prep meta-prep-author',
  36. sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
  37. get_author_posts_url( get_the_author_meta( 'ID' ) ),
  38. sprintf( esc_attr__( 'View all posts by %s', 'twentyten' ), get_the_author() ),
  39. get_the_author()
  40. )
  41. );
  42. ?>
  43. <span class="meta-sep">|</span>
  44. <?php
  45. printf( __( '<span class="%1$s">Published</span> %2$s', 'twentyten' ),
  46. 'meta-prep meta-prep-entry-date',
  47. sprintf( '<span class="entry-date"><abbr class="published" title="%1$s">%2$s</abbr></span>',
  48. esc_attr( get_the_time() ),
  49. get_the_date()
  50. )
  51. );
  52. if ( wp_attachment_is_image() ) {
  53. echo ' <span class="meta-sep">|</span> ';
  54. $metadata = wp_get_attachment_metadata();
  55. printf( __( 'Full size is %s pixels', 'twentyten' ),
  56. sprintf( '<a href="%1$s" title="%2$s">%3$s &times; %4$s</a>',
  57. wp_get_attachment_url(),
  58. esc_attr( __( 'Link to full-size image', 'twentyten' ) ),
  59. $metadata['width'],
  60. $metadata['height']
  61. )
  62. );
  63. }
  64. ?>
  65. <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?>
  66. </div><!-- .entry-meta -->
  67.  
  68. <div class="entry-content">
  69. <div class="entry-attachment">
  70. <?php if ( wp_attachment_is_image() ) :
  71. $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' ) ) );
  72. foreach ( $attachments as $k => $attachment ) {
  73. if ( $attachment->ID == $post->ID )
  74. break;
  75. }
  76. $k++;
  77. // If there is more than 1 image attachment in a gallery
  78. if ( count( $attachments ) > 1 ) {
  79. if ( isset( $attachments[ $k ] ) )
  80. // get the URL of the next image attachment
  81. $next_attachment_url = get_attachment_link( $attachments[ $k ]->ID );
  82. else
  83. // or get the URL of the first image attachment
  84. $next_attachment_url = get_attachment_link( $attachments[ 0 ]->ID );
  85. } else {
  86. // or, if there's only 1 image attachment, get the URL of the image
  87. $next_attachment_url = wp_get_attachment_url();
  88. }
  89. ?>
  90. <p class="attachment"><a href="<?php echo $next_attachment_url; ?>" title="<?php echo esc_attr( get_the_title() ); ?>" rel="attachment"><?php
  91. $attachment_width = apply_filters( 'twentyten_attachment_size', 900 );
  92. $attachment_height = apply_filters( 'twentyten_attachment_height', 900 );
  93. echo wp_get_attachment_image( $post->ID, array( $attachment_width, $attachment_height ) ); // filterable image width with, essentially, no limit for image height.
  94. ?></a></p>
  95.  
  96. <div id="nav-below" class="navigation">
  97. <div class="nav-previous"><?php previous_image_link( false ); ?></div>
  98. <div class="nav-next"><?php next_image_link( false ); ?></div>
  99. </div><!-- #nav-below -->
  100. <?php else : ?>
  101. <a href="<?php echo wp_get_attachment_url(); ?>" title="<?php echo esc_attr( get_the_title() ); ?>" rel="attachment"><?php echo basename( get_permalink() ); ?></a>
  102. <?php endif; ?>
  103. </div><!-- .entry-attachment -->
  104. <div class="entry-caption"><?php if ( !empty( $post->post_excerpt ) ) the_excerpt(); ?></div>
  105.  
  106. <?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?>
  107. <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
  108.  
  109. </div><!-- .entry-content -->
  110.  
  111. <div class="entry-utility">
  112. <?php twentyten_posted_in(); ?>
  113. <?php edit_post_link( __( 'Edit', 'twentyten' ), ' <span class="edit-link">', '</span>' ); ?>
  114. </div><!-- .entry-utility -->
  115. </div><!-- #post-## -->
  116.  
  117. <?php comments_template(); ?>
  118.  
  119. <?php endwhile; // end of the loop. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement