我们知道 WordPress 可以在后台设置一张特色图片作为日志缩略图,但是我们如何获取这张特色图片的地址呢?
1 2 3 4 5 6 7 8 9 10 11
   | <?php function get_post_thumbnail_url($post_id){         $post_id = ( null === $post_id ) ? get_the_ID() : $post_id;         $thumbnail_id = get_post_thumbnail_id($post->ID);         if($thumbnail_id ){                 $thumb = wp_get_attachment_image_src($thumbnail_id, 'thumbnail');                 return $thumb[0];         }else{                 return false;         } }
   | 
 
将上面的代码复制到当前主题的 functions.php 或者单独保存为一个插件并上传激活。使用下面方法调用:
1
   | $post_thumbnail_url = get_post_thumbnail_url($post->ID);
   |