內容簡介
如需將文章縮圖圖片裁剪為 200×300 像素,請使用以下程式碼:
<?php
the_post();
img(200, 300);
?>
此程式碼會驗證文章縮圖是否存在,並裁剪圖片、將其保存在 uploads 資料夾中,然後產生一個圖片標籤。
若要驗證文章縮圖是否存在,您可以使用 has_img()
<?php if (has_img()): ?>
<figure>
<?php img(200, 300) ?>
<figcaption>一些文字</figcaption>
</figure>
<?php endif ?>
若要裁剪非文章縮圖的圖片,您可以使用 crop($url, $size)
<?php
$cropped_url= crop( get_bloginfo('url') . '/wp-content/uploads/image.jpg', array(200, 300) );
?>
<img src="<?php echo $cropped_url ?>">
外掛標籤
開發者團隊
原文外掛簡介
For cropping a post thumbnail image to 200×300 pixels:
This will verify the existence of post thumbnail, crop the image, save it in uploads folder, and generate an image tag.
To verify the existence of a post thumbnail, you can use has_img()
To crop images that are not post thumbnails, you can use crop($url, $size)
