I have some php code which echos the width of a specific image size in WordPress. Currently, if the image width is greater than 80, then it echos “frog”…what I would like it to do is count all of the image widths within my while and if the total of those images are greater than 600 (hypothetical number) then echo “frog”. The code I am using looks like (I am using this code within my while):
<?php
$image = wp_get_attachment_image_src (get_post_thumbnail_id($post_id), 'gallery-thumbnail');
list($width) = getimagesize($image[0]);
echo $width;
if( $width > 80 ) {
echo "frog";
}
?>
My while is the basic WordPress standard:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<!-- some code here -->
<?php endwhile; else: ?>
<!-- some code here -->
<?php endif; ?>
Any ideas?
Thanks, Josh
Part pseudo code/part solution:
$sumOfWidths = 0;
Simply put the above code loops through each image and adds the image width to the
$sumOfWidthsvariable.After the foreach loop, has completed, there should be a number in the
$sumOfWidthswhich you can check and then undertake your logic as you see fit.Have a look at this code snippet to get you started