Shark Deng

Interactive Designer @Shanju Design in Shanghai

touched caffe / mxnet / python / wordpress / bootstrap / Arduino / Raspberry Pi / webgl / three.js / PIXI / 3dMax

Email

Github

WordPress – 获取文章特色图片

2019-11-20 17:20:42

WordPress获取特色图像地址主要需要用到两个函数get_post_thumbnail_id和wp_get_attachment_image_src。下面是分别获取小、中、大、完整、指定图片规格的图片地址的方法。

获取特色图像:小
$thumbnail_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), ‘thumbnail’);
echo $thumbnail_image_url[0];
?>获取特色图像:中
$medium_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), ‘medium’);
echo $medium_image_url[0];
?>获取特色图像:大
$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), ‘large’);
echo $large_image_url[0];
?>获取特色图像:完整
$full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), ‘full’);
echo $full_image_url[0];
?>获取特色图像:指定100×100
$array_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array(100,100));
echo $array_image_url[0];
?>


——By SharkDeng
如果你喜欢我的文章,欢迎红包赞赏

Leave a Reply

Your email address will not be published. Required fields are marked *