wp/wp-content/themes/twentytwelve/image.php
author ymh <ymh.work@gmail.com>
Mon, 14 Oct 2019 17:39:30 +0200
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
permissions -rw-r--r--
resynchronize code repo with production
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * The template for displaying image attachments
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     5
 * @link https://codex.wordpress.org/Template_Hierarchy
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
 * @subpackage Twenty_Twelve
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
 * @since Twenty Twelve 1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
get_header(); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
	<div id="primary" class="site-content">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
		<div id="content" role="main">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    17
		<?php
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    18
		while ( have_posts() ) :
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    19
			the_post();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    20
?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
				<article id="post-<?php the_ID(); ?>" <?php post_class( 'image-attachment' ); ?>>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
					<header class="entry-header">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
						<h1 class="entry-title"><?php the_title(); ?></h1>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
						<footer class="entry-meta">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
							<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
								$metadata = wp_get_attachment_metadata();
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    29
								printf(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    30
									__( '<span class="meta-prep meta-prep-entry-date">Published </span> <span class="entry-date"><time class="entry-date" datetime="%1$s">%2$s</time></span> at <a href="%3$s" title="Link to full-size image">%4$s &times; %5$s</a> in <a href="%6$s" title="Return to %7$s" rel="gallery">%8$s</a>.', 'twentytwelve' ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
									esc_attr( get_the_date( 'c' ) ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
									esc_html( get_the_date() ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
									esc_url( wp_get_attachment_url() ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
									$metadata['width'],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
									$metadata['height'],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
									esc_url( get_permalink( $post->post_parent ) ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
									esc_attr( strip_tags( get_the_title( $post->post_parent ) ) ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
									get_the_title( $post->post_parent )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
								);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
							?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
							<?php edit_post_link( __( 'Edit', 'twentytwelve' ), '<span class="edit-link">', '</span>' ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
						</footer><!-- .entry-meta -->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
						<nav id="image-navigation" class="navigation" role="navigation">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
							<span class="previous-image"><?php previous_image_link( false, __( '&larr; Previous', 'twentytwelve' ) ); ?></span>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
							<span class="next-image"><?php next_image_link( false, __( 'Next &rarr;', 'twentytwelve' ) ); ?></span>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
						</nav><!-- #image-navigation -->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
					</header><!-- .entry-header -->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
					<div class="entry-content">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
						<div class="entry-attachment">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
							<div class="attachment">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
/*
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
 * Grab the IDs of all the image attachments in a gallery so we can get the URL of the next adjacent image in a gallery,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
 * or the first image (if we're looking at the last image in a gallery), or, in a gallery of one, just the link to that image file
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    59
$attachments = array_values(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    60
	get_children(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    61
		array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    62
			'post_parent'    => $post->post_parent,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    63
			'post_status'    => 'inherit',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    64
			'post_type'      => 'attachment',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    65
			'post_mime_type' => 'image',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    66
			'order'          => 'ASC',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    67
			'orderby'        => 'menu_order ID',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    68
		)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    69
	)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    70
);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
foreach ( $attachments as $k => $attachment ) :
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    72
	if ( $attachment->ID == $post->ID ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
		break;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    74
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
endforeach;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
// If there is more than 1 attachment in a gallery
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
if ( count( $attachments ) > 1 ) :
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    79
	$k++;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
	if ( isset( $attachments[ $k ] ) ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
		// get the URL of the next image attachment
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
		$next_attachment_url = get_attachment_link( $attachments[ $k ]->ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
	else :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
		// or get the URL of the first image attachment
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    85
		$next_attachment_url = get_attachment_link( $attachments[0]->ID );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
	endif;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
else :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
	// or, if there's only 1 image, get the URL of the image
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
	$next_attachment_url = wp_get_attachment_url();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
endif;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
?>
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    92
								<a href="<?php echo esc_url( $next_attachment_url ); ?>" title="<?php the_title_attribute(); ?>" rel="attachment">
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    93
													<?php
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    94
													/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    95
													 * Filter the image attachment size to use.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    96
													 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    97
													 * @since Twenty Twelve 1.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    98
													 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    99
													 * @param array $size {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   100
													 *     @type int The attachment height in pixels.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   101
													 *     @type int The attachment width in pixels.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   102
													 * }
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   103
													 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   104
													$attachment_size = apply_filters( 'twentytwelve_attachment_size', array( 960, 960 ) );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   105
													echo wp_get_attachment_image( $post->ID, $attachment_size );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   106
								?>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   107
								</a>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
								<?php if ( ! empty( $post->post_excerpt ) ) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
								<div class="entry-caption">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
									<?php the_excerpt(); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
								</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
								<?php endif; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
							</div><!-- .attachment -->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
						</div><!-- .entry-attachment -->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
						<div class="entry-description">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
							<?php the_content(); ?>
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   120
							<?php
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   121
							wp_link_pages(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   122
								array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   123
									'before' => '<div class="page-links">' . __( 'Pages:', 'twentytwelve' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   124
									'after'  => '</div>',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   125
								)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   126
							);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   127
?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
						</div><!-- .entry-description -->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
					</div><!-- .entry-content -->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
				</article><!-- #post -->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
				<?php comments_template(); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
			<?php endwhile; // end of the loop. ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
		</div><!-- #content -->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
	</div><!-- #primary -->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   141
<?php get_footer(); ?>