image.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * The template for displaying image attachments
  4. *
  5. * @package WordPress
  6. * @subpackage Twenty_Twenty_One
  7. * @since Twenty Twenty-One 1.0
  8. */
  9. get_header();
  10. // Start the loop.
  11. while ( have_posts() ) {
  12. the_post();
  13. ?>
  14. <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  15. <header class="entry-header alignwide">
  16. <?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
  17. </header><!-- .entry-header -->
  18. <div class="entry-content">
  19. <figure class="wp-block-image">
  20. <?php
  21. /**
  22. * Filter the default image attachment size.
  23. *
  24. * @since Twenty Twenty-One 1.0
  25. *
  26. * @param string $image_size Image size. Default 'full'.
  27. */
  28. $image_size = apply_filters( 'twenty_twenty_one_attachment_size', 'full' );
  29. echo wp_get_attachment_image( get_the_ID(), $image_size );
  30. ?>
  31. <?php if ( wp_get_attachment_caption() ) : ?>
  32. <figcaption class="wp-caption-text"><?php echo wp_kses_post( wp_get_attachment_caption() ); ?></figcaption>
  33. <?php endif; ?>
  34. </figure><!-- .wp-block-image -->
  35. <?php
  36. the_content();
  37. wp_link_pages(
  38. array(
  39. 'before' => '<nav class="page-links" aria-label="' . esc_attr__( 'Page', 'twentytwentyone' ) . '">',
  40. 'after' => '</nav>',
  41. /* translators: %: Page number. */
  42. 'pagelink' => esc_html__( 'Page %', 'twentytwentyone' ),
  43. )
  44. );
  45. ?>
  46. </div><!-- .entry-content -->
  47. <footer class="entry-footer default-max-width">
  48. <?php
  49. // Check if there is a parent, then add the published in link.
  50. if ( wp_get_post_parent_id( $post ) ) {
  51. echo '<span class="posted-on">';
  52. printf(
  53. /* translators: %s: Parent post. */
  54. esc_html__( 'Published in %s', 'twentytwentyone' ),
  55. '<a href="' . esc_url( get_the_permalink( wp_get_post_parent_id( $post ) ) ) . '">' . esc_html( get_the_title( wp_get_post_parent_id( $post ) ) ) . '</a>'
  56. );
  57. echo '</span>';
  58. } else {
  59. // Edit post link.
  60. edit_post_link(
  61. sprintf(
  62. /* translators: %s: Post title. Only visible to screen readers. */
  63. esc_html__( 'Edit %s', 'twentytwentyone' ),
  64. '<span class="screen-reader-text">' . get_the_title() . '</span>'
  65. ),
  66. '<span class="edit-link">',
  67. '</span>'
  68. );
  69. }
  70. // Retrieve attachment metadata.
  71. $metadata = wp_get_attachment_metadata();
  72. if ( $metadata ) {
  73. printf(
  74. '<span class="full-size-link"><span class="screen-reader-text">%1$s</span><a href="%2$s">%3$s &times; %4$s</a></span>',
  75. esc_html_x( 'Full size', 'Used before full size attachment link.', 'twentytwentyone' ), // phpcs:ignore WordPress.Security.EscapeOutput
  76. esc_url( wp_get_attachment_url() ),
  77. absint( $metadata['width'] ),
  78. absint( $metadata['height'] )
  79. );
  80. }
  81. if ( wp_get_post_parent_id( $post ) ) {
  82. // Edit post link.
  83. edit_post_link(
  84. sprintf(
  85. /* translators: %s: Post title. Only visible to screen readers. */
  86. esc_html__( 'Edit %s', 'twentytwentyone' ),
  87. '<span class="screen-reader-text">' . get_the_title() . '</span>'
  88. ),
  89. '<span class="edit-link">',
  90. '</span><br>'
  91. );
  92. }
  93. ?>
  94. </footer><!-- .entry-footer -->
  95. </article><!-- #post-<?php the_ID(); ?> -->
  96. <?php
  97. // If comments are open or there is at least one comment, load up the comment template.
  98. if ( comments_open() || get_comments_number() ) {
  99. comments_template();
  100. }
  101. } // End the loop.
  102. get_footer();