G
G
ggok2019-10-12 20:58:45
htaccess
ggok, 2019-10-12 20:58:45

acf plugin, how to display thumbnail image?

Hello. In single.php I display the image with the following code:

<?php 
$image = get_field('image');
if( !empty($image) ): ?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php endif; ?>

Is it possible to specify in the code to display an image in a thumbnail? (in the settings I have a thumbnail 100x100)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
WP Panda, 2019-10-12
@ggok

Store the image as an ID, there is such an option. Then output like this

$image = get_field('image');
if( !empty( $image ) ) {
    echo wp_get_attachment_image( $image, 'thumbnail' );

If it is important to store as an array, then the simplest option is this.
Connect https://github.com/bfintal/bfi_thumb
And output like this
<?php 
$image = get_field('image');
if( !empty($image) ): 
$thumb = bfi_thumb( $image['url'], ['width' => 100, 'height' => 100, 'crop' => true] );
printf('<img src="%s" alt="%s" />',$thumb, $image['alt'])
endif; ?>

L
Leonid Smirnov, 2019-11-16
@SunyJun

It is strange that you do not use the search, because the answer to your question is described in detail here - https://www.pandoge.com/stati-i-sovety/poluchaem-p...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question