Load resized image in wordpress

Asked

Viewed 41 times

0

Good night. I’m only trying to upload the "thumbnails" of the images on my custom page, but the site loads the original image and resizes it. That weighs the load on my site.

My code:

<?php if ( $the_query->have_posts() ): ?>
    <div class="row" id="products">
        <?php while ( $the_query->have_posts() ): ?>
            <?php $the_query->the_post(); ?>
            <div class="col-xs-12 col-sm-4 col-md-3 product" alt="<?php get_the_title() ?>" title="<?php get_the_title() ?>">
                <div class="change">
                    <i class="fa fa-undo" aria-hidden="true"></i>
                </div>
                <a href="<?php echo get_permalink() ?>">
                    <?php if(types_render_field('lancamento')=="Sim"): ?>
                    <div class="new <?php echo strtolower(types_render_field('tipo')) ?>">
                        <h1>Lançamento</h1>
                    </div>
                    <?php endif; ?>
                    <div class="img top">
                        <img alt="<?php get_the_title() ?>" title="<?php get_the_title() ?>" src="<?php echo types_render_field("logo", array("width"=>"200","height"=>"200", "raw" => "true")); ?>" class="img-responsive"/>
                    </div>
                    <div class="img botton">
                        <img alt="<?php get_the_title() ?>" title="<?php get_the_title() ?>" src="<?php echo types_render_field("miniatura", array("size"=>"medium", "raw" => "true")); ?>" class="img-responsive"/>
                    </div>
                </a>
            </div>
        <?php endwhile; ?>
    </div>
<?php endif; ?>

The Divs "img top" and "img Botton" and my 2 tests did not work, are the image loading blocks, however, the result is not what I wanted.

Imagery: inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

1 answer

0

I don’t know if it’s your case, but when you upload the images via Wordpress media library, it creates several versions of the image with different dimensions in the directory wp-content/uploads.

Make sure there are these variations. Then, just adapt your code to get the version of the image in the size that is most convenient.

  • I am trying to get specific resolution image in wp-content/uploads, but to no avail. I am using Toolset types_render_field. https://toolset.com/documentation/customizing-sites-using-php/functions/

  • Wouldn’t it be simpler for you to simply add the image prefix to its dimension? For example, if in the uploads folder you have the image "test-150x150.jpg" it would not be the case to make only one <?php echo $prefixo_da_imagem . "-150x150.jpg" ?> ?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.