So I am pulling in post thumbnails using a WP query / loop. I have various different loops but I always want the aspect ratio to be 4/3, i.e. the height is always 75% of the width.
Now setting it in px would be rather easy, but since the width of the thumbnail changes a lot, I am looking to apply a universal class to all the thumbnails.
The thumbnail part of the loop looks like this. I thought this would work with calc (width * 0.75)
. That doesnt work, as I assume the width would have to be set in pixels for that to function?
Another option I explored was add_image_size as a function and then call in the_post_thumbnail, but that would mean I would have to use pixels.
Any ideas?
.category-thumbnail-header {
width: 100%;
object-fit: cover;
}
<?php if ( has_post_thumbnail() ) { ?>
<a href="<?php the_permalink(); ?>" >
<?php the_post_thumbnail( 'large', array(
'class' => 'category-thumbnail-header',
'alt' => get_the_title()
) );
?>
</a>
<?php }?>
<a href="https://smartinvestor.local/2020/02/18/aktien-update-agnico-eagle-mines/" >
<img
width="1024" height="1024"
src="https://smartinvestor.local/wp-content/uploads/2020/02/curioso-photography-pqN82ZS6OsI-unsplash-1024x1024.jpg"
class="category-thumbnial-header wp-post-image"
alt="Aktien-Update: Agnico Eagle Mines"
srcset=""
sizes="(max-width: 1024px) 100vw, 1024px" />
</a>