以不同分辨率裁剪特征图像



如何在WordPress中以中等、大、完整和缩略图等不同分辨率裁剪特色图像。我想看起来像这种决心。例如:200x200、300x300等等。我正在尝试这个代码。但这不起作用。请解决这个问题。<?php $thumb_id = get_post_thumbnail_id(); $thumb_url = wp_get_attachment_image_src($thumb_id, array(200,200), true);?> <a href="<?php echo $thumb_url[0];?>" download="image-200x200" target="_blank">200x200</a> ?>

将以下代码添加到functions.php,以创建一个名为my_image_size的自定义图像大小300x200。

        add_image_size( 'my_image_size', 300, 200, true );

将以下代码添加到模板中,以便在其中显示具有创建的自定义图像大小的特色图像。

    <?php 
        if ( has_post_thumbnail() ) { 
            the_post_thumbnail( 'my_image_size' ); 
        }
    ?>
Check this url https://github.com/bfintal/bfi_thumb 
include BFI_Thumb.php file in function.php file.

<?php echo bfi_thumb( "image1.jpg",  array( 'width' => 150, 'height' => 150 )); ?>
<?php echo bfi_thumb( "image1.jpg",  array( 'width' => 300, 'height' => 300 )); ?>
<?php echo bfi_thumb( "image1.jpg",  array( 'width' => 500, 'height' => 500 )); ?>
<?php echo bfi_thumb( "image1.jpg",  array( 'width' => 768, 'height' => 768 )); ?>
<?php echo bfi_thumb( "image1.jpg",  array( 'width' => 980, 'height' => 980 )); ?>
You can add any size of image crop and display in website.

最新更新