2

That's my loop:

<main id="main">

    <?php 
    // the query
    $args = array('posts_per_page' => 10 );
    $the_query = new WP_Query( $args ); 

    ?>

    <?php if ( $the_query->have_posts() ) { ?>

        <!-- loop -->

        <?php while ( $the_query->have_posts() ) {

                    $the_query->the_post(); ?>

            <div id="thumbnail">

                <?php
                if ( has_post_thumbnail() ) { the_post_thumbnail(array( "class"=>"thumbnail")); } ?>

        </div>

       <h2><a href="<?php the_permalink();?>"><?php the_title(); ?></a></h2>

       <div class="entry">

            <?php the_excerpt(); ?>

       </div>

    <?php } } else { ?>
    <p><?php _e( 'Die Posts entsprechen leider nicht den Kriterien.' ); ?></p>
    <?php }  ?>

   <!-- end of the loop -->

   <?php wp_reset_postdata(); ?>

I want to use instead of 150x150px 200x200px but nothing works for me. Images should be crop.

Currently it looks like this: http://prnt.sc/b3v88w

I tried set_post_thumbnail_size( 200, 200 ); but any changes...

1

3 Answers 3

2

set_post_thumbnail_size() (and other API functions which add/change sizes) applies to generation while it's active. So existing generated image sizes won't be retroactively affected by it.

There are plenty of tools around (plugins, wp-cli) which regenerate files with current sizes configuration.

1

In your function.php you can add a custom size, for example: add_image_size ('custom_thumbail', 200, 200); Then once you regenerate thumbnails (recommended plugin by wordpress) it will create these, or any new uploaded images will have this size.

Then you can call them in your post.

Echo wp_get_attachment_url('your post id', 'custom_thumbail');

https://developer.wordpress.org/reference/functions/add_image_size/

1

I use the Aqua Resizer in my theme development. https://github.com/syamilmj/Aqua-Resizer

It's pretty easy to implement, and it should do exactly what you want. This function will allow you to resize any existing WordPress image. The below example would create a 200 x 200 image from the WP Medium image, and hard crop it to 200 x 200.

$thumb = get_post_thumbnail_id();
$img_url = wp_get_attachment_url( $thumb,'medium' ); //get full URL to image 
$image = aq_resize( $img_url, 200, 200, true ); //resize & crop the image

Then to call the image...

    <?php if($image) : ?>
        <img src="<?php echo $image ?>"/>
    <?php endif; ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.