attachment.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * Attachment template
  4. *
  5. * @package vamtam/consulting
  6. */
  7. VamtamFramework::set( 'page_title', esc_html__( 'Attachment', 'vamtam-consulting' ) );
  8. get_header();
  9. ?>
  10. <?php if ( have_posts() ) : the_post(); ?>
  11. <div class="row page-wrapper">
  12. <?php VamtamTemplates::$in_page_wrapper = true; ?>
  13. <article id="post-<?php the_ID(); ?>" <?php post_class( VamtamTemplates::get_layout() ); ?>>
  14. <div class="page-content">
  15. <?php rewind_posts() ?>
  16. <div class="entry-attachment">
  17. <?php if ( wp_attachment_is_image() ) :
  18. $attachments = array_values( get_children( array(
  19. 'post_parent' => $post->post_parent,
  20. 'post_status' => 'inherit',
  21. 'post_type' => 'attachment',
  22. 'post_mime_type' => 'image',
  23. 'order' => 'ASC',
  24. 'orderby' => 'menu_order ID',
  25. ) ) );
  26. foreach ( $attachments as $k => $attachment ) {
  27. if ( $attachment->ID == $post->ID ) {
  28. break;
  29. }
  30. }
  31. $k++;
  32. // If there is more than 1 image attachment in a gallery
  33. if ( count( $attachments ) > 1 ) {
  34. if ( isset( $attachments[ $k ] ) ) {
  35. // get the URL of the next image attachment
  36. $next_attachment_url = get_attachment_link( $attachments[ $k ]->ID );
  37. } else {
  38. // or get the URL of the first image attachment
  39. $next_attachment_url = get_attachment_link( $attachments[0]->ID );
  40. }
  41. } else {
  42. // or, if there's only 1 image attachment, get the URL of the image
  43. $next_attachment_url = wp_get_attachment_url();
  44. }
  45. ?>
  46. <p class="attachment"><a href="<?php echo esc_url( $next_attachment_url ) ?>" title="<?php the_title_attribute(); ?>" rel="attachment" class="thumbnail"><?php
  47. $attachment_size = apply_filters( 'vamtam_attachment_size', 900 );
  48. echo wp_get_attachment_image( $post->ID, array( $attachment_size, 9999 ) );
  49. ?></a></p>
  50. <div id="nav-below" class="navigation">
  51. <div class="nav-previous"><?php previous_image_link( false ); ?></div>
  52. <div class="nav-next"><?php next_image_link( false ); ?></div>
  53. </div><!-- #nav-below -->
  54. <?php else : ?>
  55. <a href="<?php echo esc_url( wp_get_attachment_url() ) ?>" title="<?php the_title_attribute(); ?>" rel="attachment"><?php the_title() ?></a>
  56. <?php endif; ?>
  57. </div><!-- .entry-attachment -->
  58. <div class="entry-caption">
  59. <?php
  60. if ( ! empty( $post->post_excerpt ) ) {
  61. the_excerpt();
  62. }
  63. ?>
  64. <?php
  65. if ( wp_attachment_is_image() ) {
  66. $metadata = wp_get_attachment_metadata();
  67. printf( esc_html__( 'Original size is %s pixels', 'vamtam-consulting' ),
  68. sprintf( '<a href="%1$s" title="%2$s">%3$s &times; %4$s</a>',
  69. esc_url( wp_get_attachment_url() ),
  70. esc_attr__( 'Link to full-size image', 'vamtam-consulting' ),
  71. intval( $metadata['width'] ),
  72. intval( $metadata['height'] )
  73. )
  74. );
  75. }
  76. ?>
  77. </div>
  78. <?php the_content( wp_kses_post( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'vamtam-consulting' ) ) ); ?>
  79. <?php get_template_part( 'templates/share' ); ?>
  80. </div>
  81. </article>
  82. <?php get_template_part( 'sidebar' ) ?>
  83. </div>
  84. <?php endif ?>
  85. <?php get_footer(); ?>