Closed mailmilisku closed 11 years ago
Basically, you want to to grab the first image from the attachments, so first, store all your attachments in an array like so:
$images = array();
foreach ( $attachments as $thumb_id => $attachment )
$images[] = wp_get_attachment_image($thumb_id, $size);
}
then to grab the first image url,
$first_img = '';
if(!empty($images)) $first_img = $images[0];
Now you can do your conditional check:
if(has_post_thumbnail()) {
// resize post thumbnail here e.g. $img_url = aq_resize...
} elseif($first_img) {
// resize the first img here, $img_url = aq_resize($first_img, ...
} else {
// $img_url = ''; //empty
}
Hope that helps
Great! Thank you, Syamil. Do you implement this code for your theme on Themeforest? Which one? If so, I want to buy.
Nope sorry, none of my themes does this.
Will be great for the next user if you add the sample code here: https://github.com/sy4mil/Aqua-Resizer/wiki/Examples
Once again, thank for your great work.
It's actually a WP question, not aqua resizer's question. :)
Cheers
Is it possible to combine feature image or first image in post as the thumbnail? In case user don't set up feature image, automatically will use the first post image as thumbnail. In traditional way, I use this code:
How can I implement these code when I'm using Aqua-resizer? Or maybe you have better solution? Thanks in advance.