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

/attachment.php

https://github.com/blackandblack/bb_boilerplate
PHP | 100 lines | 88 code | 0 blank | 12 comment | 12 complexity | 42904c96190946f1d6fba0b50fc12704 MD5 | raw file
Possible License(s): MIT
  1. <?php
  2. /**
  3. * The template for displaying attachments.
  4. *
  5. * @package WordPress
  6. * @subpackage Boilerplate
  7. * @since Boilerplate 1.0
  8. */
  9. include_once 'includes.php';
  10. get_header(); ?>
  11. <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
  12. <?php if ( ! empty( $post->post_parent ) ) : ?>
  13. <p class="page-title"><a href="<?php echo get_permalink( $post->post_parent ); ?>" title="<?php esc_attr( printf( __( 'Return to %s', 'boilerplate' ), get_the_title( $post->post_parent ) ) ); ?>" rel="gallery"><?php
  14. /* translators: %s - title of parent post */
  15. printf( __( '<span class="meta-nav">&larr;</span> %s', 'boilerplate' ), get_the_title( $post->post_parent ) );
  16. ?></a></p>
  17. <?php endif; ?>
  18. <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  19. <h2 class="entry-title"><?php the_title(); ?></h2>
  20. <div class="entry-meta">
  21. <?php
  22. printf(__('By %2$s', 'boilerplate'),
  23. 'meta-prep meta-prep-author',
  24. sprintf( '<a class="url fn n" href="%1$s" title="%2$s">%3$s</a>',
  25. get_author_posts_url( get_the_author_meta( 'ID' ) ),
  26. sprintf( esc_attr__( 'View all posts by %s', 'boilerplate' ), get_the_author() ),
  27. get_the_author()
  28. )
  29. );
  30. ?>
  31. <span>|</span>
  32. <?php
  33. printf( __('Published %2$s', 'boilerplate'),
  34. 'meta-prep meta-prep-entry-date',
  35. sprintf( '<abbr title="%1$s">%2$s</abbr>',
  36. esc_attr( get_the_time() ),
  37. get_the_date()
  38. )
  39. );
  40. if ( wp_attachment_is_image() ) {
  41. echo ' | ';
  42. $metadata = wp_get_attachment_metadata();
  43. printf( __( 'Full size is %s pixels', 'boilerplate'),
  44. sprintf( '<a href="%1$s" title="%2$s">%3$s &times; %4$s</a>',
  45. wp_get_attachment_url(),
  46. esc_attr( __('Link to full-size image', 'boilerplate') ),
  47. $metadata['width'],
  48. $metadata['height']
  49. )
  50. );
  51. }
  52. ?>
  53. <?php edit_post_link( __( 'Edit', 'boilerplate' ), '', '' ); ?>
  54. </div><!-- .entry-meta -->
  55. <div class="entry-content">
  56. <div class="entry-attachment">
  57. <?php if ( wp_attachment_is_image() ) :
  58. $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' ) ) );
  59. foreach ( $attachments as $k => $attachment ) {
  60. if ( $attachment->ID == $post->ID )
  61. break;
  62. }
  63. $k++;
  64. // If there is more than 1 image attachment in a gallery
  65. if ( count( $attachments ) > 1 ) {
  66. if ( isset( $attachments[ $k ] ) )
  67. // get the URL of the next image attachment
  68. $next_attachment_url = get_attachment_link( $attachments[ $k ]->ID );
  69. else
  70. // or get the URL of the first image attachment
  71. $next_attachment_url = get_attachment_link( $attachments[ 0 ]->ID );
  72. } else {
  73. // or, if there's only 1 image attachment, get the URL of the image
  74. $next_attachment_url = wp_get_attachment_url();
  75. }
  76. ?>
  77. <p><a href="<?php echo $next_attachment_url; ?>" title="<?php echo esc_attr( get_the_title() ); ?>" rel="attachment"><?php
  78. $attachment_size = apply_filters( 'boilerplate_attachment_size', 900 );
  79. echo wp_get_attachment_image( $post->ID, array( $attachment_size, 9999 ) ); // filterable image width with, essentially, no limit for image height.
  80. ?></a></p>
  81. <nav id="nav-below" class="navigation">
  82. <div class="nav-previous"><?php previous_image_link( false ); ?></div>
  83. <div class="nav-next"><?php next_image_link( false ); ?></div>
  84. </nav><!-- #nav-below -->
  85. <?php else : ?>
  86. <a href="<?php echo wp_get_attachment_url(); ?>" title="<?php echo esc_attr( get_the_title() ); ?>" rel="attachment"><?php echo basename( get_permalink() ); ?></a>
  87. <?php endif; ?>
  88. </div><!-- .entry-attachment -->
  89. <div class="entry-caption"><?php if ( !empty( $post->post_excerpt ) ) the_excerpt(); ?></div>
  90. <?php the_content( __( 'Continue reading &rarr;', 'boilerplate' ) ); ?>
  91. <?php wp_link_pages( array( 'before' => '' . __( 'Pages:', 'boilerplate' ), 'after' => '' ) ); ?>
  92. <footer class="entry-utility">
  93. <?php boilerplate_posted_in(); ?>
  94. <?php edit_post_link( __( 'Edit', 'boilerplate' ), ' <span class="edit-link">', '</span>' ); ?>
  95. </footer><!-- .entry-utility -->
  96. <?php comments_template(); ?>
  97. </div><!-- .entry-content -->
  98. </article>
  99. <?php endwhile; ?>
  100. <?php get_footer(); ?>