Skip to content

Instantly share code, notes, and snippets.

@taniarascia
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taniarascia/1ac171eaf23439f78941 to your computer and use it in GitHub Desktop.
Save taniarascia/1ac171eaf23439f78941 to your computer and use it in GitHub Desktop.
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