Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Force uploaded media to create a certain thumbnail size
// Add 250 x 250 thumbnail to every image uploaded
add_image_size( 'gallery-thumbnail', 250, 250, true );
// gallery_thumbnail is a custom size! It can have any name.
// Call it later in a gallery loop.
<section id="gallery_page">
<ul class="gal columns-4">
<?php
$args = array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'orderby' => 'post_date',
'order' => 'desc',
'posts_per_page' => '50',
'post_status' => 'inherit',
'category_name' => 'Gallery Page'
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'gallery-thumbnail' );
$url = $thumb['0'];
$image = wp_get_attachment_image_src( get_the_ID() );
echo "<li><img src='" . $thumb[0] . "'></li>";
endwhile; ?>
</ul>
</section>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment