I´m actually working at a wallpaper blog and I want to provide the possibility to download an image in different, specific, wallpaper sizes that are contained in the media library.
Until now I did the following things:
- creating a child theme
- adding some extra wallpaper image sizes to functions.php
- installing the plugin “Manual Image Crop” that allows me to crop all available image sizes individually (Link to Plugin: https://de.wordpress.org/plugins/manual-image-crop/)
- include the wallpaper images to posts and selecting “link to attachment file”
- adding “attachment.php” with some styling to my child theme.
-
adding the following code to the attachment.php that I found on this website: https://premium.wpmudev.org/blog/advanced-attachment-page/
<p class='resolutions'> Downloads: <?php $images = array(); $image_sizes = get_intermediate_image_sizes(); array_unshift( $image_sizes, 'full' ); foreach( $image_sizes as $image_size ) { $image = wp_get_attachment_image_src( get_the_ID(), $image_size ); $name = $image_size . ' (' . $image[1] . 'x' . $image[2] . ')'; $images[] = '<a href="' . $image[0] . '">' . $name . '</a>'; } echo implode( ' | ', $images ); ?> </p>
With this solution I get a nice attachment page, with a preview image an links to all the sizes of that image. Thats already good, but not good enough for me.
I would like to exclude some of the image sizes like “thumbnail”, “medium”, “large” and some extra sizes that I used for styling purposes within the theme.
Has anybody an idea how to exclude these sizes or the other way round, to select only the sizes that are needed for download?
Thanks in advance for any idea that might solve that issue
You can use this function of wordpress to declare new sizes of images:
https://developer.wordpress.org/reference/functions/add_image_size/
Ex:
add_image_size( ‘large’, 1200, 600 );
add_image_size( ‘superlarge’, 2400, 1200 );
Then you can use any of theses sizes using:
https://codex.wordpress.org/Function_Reference/the_post_thumbnail
the_post_thumbnail( ‘superlarge’ );
To regenerate all your thumbnails, use Regenerate Thumbnails plugin.
I found a solution myself. To select only specific image sizes, they have to be specified within the image_sizes array like this: