Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.
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

share|improve this question
    
Are you trying to show the masonry layout on your homepage using posts? –  sprclldr Jun 17 '13 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 –  Kirsty Harris Jun 17 '13 at 21:12
    
erikjohanssonphoto.com/work/imagecats/commissioned ... Bit like this? Theres like a variation of images –  Kirsty Harris Jun 17 '13 at 21:13
    
they have done this with wordpress so im not sure how :S –  Kirsty Harris Jun 17 '13 at 21:16
    
I'm not sure what problem you are having specifically. Have you contacted the support for your theme? –  sprclldr Jun 17 '13 at 21:29

1 Answer 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
share|improve this answer
    
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 :) –  Kirsty Harris Jun 17 '13 at 21:54
    
Start here if you are starting Masonry from scratch: wp.tutsplus.com/tutorials/theme-development/… –  sprclldr Jun 17 '13 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 –  Kirsty Harris Jun 17 '13 at 21:56
    
    
i have found this, however this function or query above im not sure where to put this, is this in the wp_query section? –  Kirsty Harris Jun 17 '13 at 21:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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