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 if page template
- Set JPEG compression for specific custom image sizes
- remove links from images using functions.php
- Issue with wp_get_attachment_image() and SVG file type
- Removing default image size list in Media Box
- How to create thumbnails for PDF uploads?
- Get recent posts with thumbnail
- How to display the_post_thumbnail if a post has one or otherwise display the first image in a post?
- How do I use element instead of tags in WordPress post content having webP support?
- Auto delete WordPress images/thumbnails (all sizes) and featured after X days/hours, or similar?
- Linking thumbnail to full size image
- Gallery images titles – get from post
- Add a Post Thumbnail to an RSS Feed with custom size
- WordPress – thumbnail image from youtube (function and loop)
- How to add a rel attribute to images that contains their categories?
- Setting featured image with function, 1 part not working
- Best way to programatically add “rel” attributes to page and post images
- img width and height attributes being set by get_the_post_thumbnail
- Count total number of images in post and echo results as number
- How to display a default image for post thumbnail using functions.php?
- How can you limit srcset on a single type of page?
- Add Featured image column into wordpress admin on pages AND posts
- Automatically wrap multiple images in div
- Image rotation fails to regenerate custom sized thumbnail
- Twentyten Child Theme: header images display messed up in admin panel
- Create a new query in function.php to filter blog posts
- Getting custom image size URL in functions
- media resize/crop possibilities?
- It does not work concatenation in function.php
- Exclude from the query posts with meta_key and meta_value
- Control the srcset much more (not all sizes in it each time)
- How to retrieve the current post’s generated featured 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
- 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’t locate custom image sizes defined by child theme
- Woocommerce image sizes missing from Appearance › Customize but not declared by theme
- Add attribute only to first image of every post via functions.php
- Need to convert image url to a Base_64 data url with wordpress function..
- Using functions.php to include code that’s processed inline
- Function to insert missing image size attributes into img tags
- How to use get_posts() function in functions.php
- Getting images from media library and get_the_date() not working
- Change custom featured image size in twentythirteen child theme
- Add_image_size not generating correct size
- Using add_image_size in functions.php to get original uploaded file
- show all the posts thumbnails
- how can I change all wordpress media file url to custom cdn url?
- How to change images url in function.php?
- Which filter fires upon setting a featured image
- Can I use ‘Featured Image’ as a hero image and a thumbnail?
- Class parameter in get_avatar args doesn’t get added to output
- remove_filter function to unhook twentysixteen parent theme function
- Images with overlay
- Sticky – Featured Image
- Why am I losing image quality on my site?
- Replace image attributes for lazyload plugin on image elements with specific class
- 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
- Zip all (original) images from media gallery
- How to exclude posts with empty and non-existent relational custom field with meta_query?
- No compression occurs on my jpegs after adding jpeg_quality hook to my functions.php file
- Update add_image_size
- Function the_content
- Set thumbnail from URL, by grabbing image in functions.php
- Dynamically adding Captions to images
- add if statement to the featured image
- 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