0
add_image_size( 'category-thumb', 250, 9999 ); //300 pixels wide (and unlimited height)

I am using the above code within my functions.php file, to generate various thumbnail sizes for my masonry portfolio theme.

<?php the_post_thumbnail(); ?>

Can the above take an array of images within this to randomise the images that is displayed within the grid?

Thanks Kirsty

8
  • Are you trying to show the masonry layout on your homepage using posts? Commented Jun 17, 2013 at 21:10
  • Hi sprclldr. I have this as a template, and ive set it as a custom template, but ive set a post thumbnail size, but i want to vary it? So like a variation dependant on the overall original picture size maybe? So if its less that 300px wide it would be 250 wide, and if it is less than 600 it would be 500 wide... if that makes sense Commented Jun 17, 2013 at 21:12
  • erikjohanssonphoto.com/work/imagecats/commissioned ... Bit like this? Theres like a variation of images Commented Jun 17, 2013 at 21:13
  • they have done this with wordpress so im not sure how :S Commented Jun 17, 2013 at 21:16
  • I'm not sure what problem you are having specifically. Have you contacted the support for your theme? Commented Jun 17, 2013 at 21:29

1 Answer 1

1

the_post_thumbnail() only retrieves the specified thumbnail size for the current post. You'll need to write a conditional function or use a custom query to randomize the posts shown or thumbnail sizes from your theme's loop.

If you are familiar with where your loop starts, then:

$tile_sizes = array('small','medium','category-thumb');

LOOP STARTS

$random_size = rand(0,2);
$chosen_size = $tile_sizes[$random_size];
the_post_thumbnail($chosen_size);

LOOP ENDS
5
  • ok i will have to look at that :) as im very new to wordpress. Ive tried to look at tutorials for this and not alot on it :) Commented Jun 17, 2013 at 21:54
  • Start here if you are starting Masonry from scratch: wp.tutsplus.com/tutorials/theme-development/… Commented Jun 17, 2013 at 21:55
  • hi sprclldr i have that, however that is restrictive to one size (220px wide), where i want to vary the sizes pulling through :S Commented Jun 17, 2013 at 21:56
  • wordpress.stackexchange.com/questions/67050/… Commented Jun 17, 2013 at 21:58
  • i have found this, however this function or query above im not sure where to put this, is this in the wp_query section? Commented Jun 17, 2013 at 21:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.