When you are in the loop, you can access the current loop item’s index by using the current_post
method. You didn’t post any code, so I’m just going for a simple demonstration.
If ( have_posts() ) {
while( have_posts() ){
the_post();
// Setting the global $wp_query to access the method
global $wp_query;
// Get the current post's index
$current_post = $wp_query->current_post;
// Let's calculate the thumbnail size based on the current post's index
switch ( $current_post ) {
case 1 :
$size="size-1";
break;
case 2 :
$size="size-2";
break;
default :
$size="post-thumbnail";
break;
}
// Now we have the proper thumbnail size
the_post_thumbnail ( $size );
}
}
Related Posts:
- Missing feature image link function
- Generating Responsive Background Image Sizes in PHP
- Why are image thumbnails cropped proportionally (not per dimensions)?
- Why are image thumbnails cropped proportionally (not per dimensions)?
- Display height and width properties with the_post_thumbnail() or related function
- Removing the first image in content
- Function to auto-set a featured image that is already in use
- wp_get_attachment_image function size argument not working if I also add a custom class
- Overwriting Parent Theme’s Image Sizes
- Can you put a condition on add_image_size() depending on the width of the uploaded image?
- Set spesific size of featured images
- Can’t generate thumbnail images
- How to hide image-url if no attachment?
- How to add a new image size and apply it to posts only?
- Featured Image keeps cropping
- Custom image sizes showing in Classic Editor only when upladed directly to post
- Can You Set A Minimum Image Dimension For Resizing Images?
- Featured image on archive page based on post type
- Printing medium sized image
- Remove Featured Images from Posts Older Than a Certain Date
- Full size image option removing problem
- Image width issue in IE [closed]
- image_size with respect to aspect ratios
- add_image_size() parameter four ($crop = true) is ignored: the_post_thumbnail() returns scaled image(s) instead of hard cropped
- Exclude from the query posts with meta_key and meta_value
- How to obtain the recent posts without their content in an efficient way?
- Control the srcset much more (not all sizes in it each time)
- How to retrieve the current post’s generated featured image size?
- Check if the image size is available and if not use ‘full’ image size
- Way to store featured image width and height in two separate variables?
- srcset and custom field get_post_meta and wp_get_attachment_url
- Limit dimensions of “Full” size images
- Visual Composer creating own shortcodes with vc_map() to return simple Image
- Test if a post exists by category and date
- Turn get_posts as string into an array for use in theme admin options
- Retrieve Image Attachments Getting Post Thumbnail Image First
- is there a way to remove featured image from blog page and single page
- How to only publish posts with image in it
- What are the meta fields for an attachment?
- Can set_post_thumbnail be used to remove a thumbnail?
- Can’t locate custom image sizes defined by child theme
- Woocommerce image sizes missing from Appearance › Customize but not declared by theme
- How to properly set custom logo size?
- Add attribute only to first image of every post via functions.php
- Need To Change WordPress Meta Tags… Includes wordpress shortcodes
- Need to convert image url to a Base_64 data url with wordpress function..
- How to Add Shortcode to html img code?
- Using functions.php to include code that’s processed inline
- Else/If Statement to Display Photo Descriptions
- Function to insert missing image size attributes into img tags
- Image Crop Not Working
- How to use get_posts() function in functions.php
- Use existing image sizes for WooCommerce
- Problem in using Customizer
- wp_get_attachment_image_src returns image on main domain, false on subdomain
- Retrieve First Image Function
- Show Featured Image in else statement
- Custom Image Size in Insert Media
- Getting images from media library and get_the_date() not working
- Change custom featured image size in twentythirteen child theme
- resizing of thumbnails not working
- Prevent creating multiple image resizes in twentytwelve template
- Conditional function for excluding first image from content, not working
- Add_image_size not generating correct size
- Using add_image_size in functions.php to get original uploaded file
- get_image_tag() html output : empty src attribute
- How to make excerpt image be full size instead of thumbnail?
- show all the posts thumbnails
- struggling with syntax for the_post_thumbnail();
- include w_thumbnail_src in function?
- Need To Resize Images Exactly Without Losing Image Details
- how can I change all wordpress media file url to custom cdn url?
- Different image using srcset function
- Is it possible to limit number of files a non-admin user can upload via the WordPress media library?
- Auto delete content in specific folder inside media library
- How to change images url in function.php?
- Which filter fires upon setting a featured image
- not outputting medium size image URL
- How to update an image attachment’s alt text from a custom field when saving a post?
- Can I use ‘Featured Image’ as a hero image and a thumbnail?
- Class parameter in get_avatar args doesn’t get added to output
- large image size of 1440×1440 not pulling 2x of 2880×2880 image
- remove_filter function to unhook twentysixteen parent theme function
- blank page with wp_get_attachment
- Exclude admins from query get posts
- (Divi): How to make WordPress load images of specific size for Blurb modules on given page with a funciton?
- Images with overlay
- Sticky – Featured Image
- Remove post from latest posts after a month only with certain tag
- restrict uploaded image size and fixed image display size
- Why am I losing image quality on my site?
- Replace image attributes for lazyload plugin on image elements with specific class
- Using Switch Statement to Change Image According to Last Digit of Topic ID
- Frontend Feature image upload not work
- Disable links to images only if link is an image
- Pagination not working on my archive page for a custom post type
- Restricted images only for logged user. (hidden url)
- Best way to add image to recent posts widget?
- Slider Thumbnail Size Issue [closed]
- same get_posts function works diffrently in tag.php and functions.php