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
- Set JPEG compression for specific custom image sizes
- How to change the markup WordPress inserts for post images
- Programmatically Set First Image as Featured
- WP 4.4. responsive loads normal image after loading the responsive image
- Get recent posts with thumbnail
- How to reduce original image quality on upload?
- Add options to featured image
- Auto delete WordPress images/thumbnails (all sizes) and featured after X days/hours, or similar?
- mysql custom wp query
- Set image size on media and text block with a function
- Remove images from get_the_excerpt
- WordPress – thumbnail image from youtube (function and loop)
- Use Exact Image Size using add_image_size
- Insert width & height attributes to all images displayed on each page
- Overwrite Parent Theme add_image_size in Child Theme
- Images uploaded using media uploader are appearing upside down
- How to add css class to image attached in all the posts?
- When to use an if statement after get_posts?
- img width and height attributes being set by get_the_post_thumbnail
- Count total number of images in post and echo results as number
- Get the 5 lastest Featured Posts from a category
- how to add an image to the footer?
- Getting Featured Image Caption to Only Show if Populated
- Can’t check if a post has thumbnail adding filter to get_post_metadata()
- Automatically wrap multiple images in div
- Post thumbnail not showing in WP admin area for custom post type
- Understanding and altering the structure of posted images
- Backstretch.js and thumbnail sizes to reduce loading time
- Publish/Update post is changing image links from file url to post url
- Featured Image Thumbnail Creation
- How to stop twenty fifteen theme from cropping featured images?
- Display images that are not in the content
- Create a new query in function.php to filter blog posts
- Remove after images
- Getting custom image size URL in functions
- Custom Loop, Match Category with Page: How to display post featured image?
- Redirect to another page using contact form 7? [closed]
- How to properly set custom logo size?
- How to Add Shortcode to html img code?
- Else/If Statement to Display Photo Descriptions
- Image Crop Not Working
- 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
- Prevent creating multiple image resizes in twentytwelve template
- Conditional function for excluding first image from content, not working
- struggling with syntax for the_post_thumbnail();
- 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
- not outputting medium size image URL
- How to update an image attachment’s alt text from a custom field when saving a post?
- large image size of 1440×1440 not pulling 2x of 2880×2880 image
- 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?
- restrict uploaded image size and fixed image display size
- Using Switch Statement to Change Image According to Last Digit of Topic ID
- Disable links to images only if link is an image
- 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
- Different body image backgrounds on different pages, posts and categories
- Apply height and width for the_content() inside youtube video tag
- Open image size links in a page instead of direct image link
- add_theme_support not outputting thumbnails
- Function to get thumbnail img source
- Integrating custom API for post content into Admin interface & Public Website [closed]
- Remove default Image Sizes
- How to resize image from import image url?
- How to add height and width dimensions automatically to archive descriptions
- How to overwrite image if it already exists – WordPress, Gravity form
- How Do I Prevent Featured Image Caption Displaying Above And Below Image
- Second featured image only shows in metabox preview after saving a post in the wordpress editor
- No src and sizes attributes present on WordPress thumbnail images; the smallest image size is loaded irregardless of viewport size