- 时间:2020-12-11 11:24 编辑:南贤俊 来源:蚂蚁资源网 阅读:166
- 扫一扫,手机访问
摘要:本文围绕WordPress 主题图片 讲述关于Wordpress 显示主题图片的实现代码的相关知识,精彩详情内容请仔细阅读以下内容。感谢支持!
大家好,今小编要介绍的是关于Wordpress 显示主题图片的实现代码的相关内容,多方面分析说明,感兴趣朋友的可以参考学习。
关键词:WordPress 主题图片
复制代码代码如下:
<?php
//Put this in functions.php
function get_primary_image($id, $size){
$featured = wp_get_attachment_image_src( get_post_thumbnail_id($id), $size, false);
if($featured){
$childURL = $featured['0'];
}else{
$children = get_children(array('post_parent' => $id, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'numberposts' => 1));
reset($children);
$childID = key($children);
//$childURL = wp_get_attachment_url($childID);
$childArray = wp_get_attachment_image_src($childID, $size, false);
$childURL = $childArray['0'];
if(empty($childURL)){
$childURL = get_bloginfo('template_url')."/images/default.png";
}
}
return($childURL);
}
//Run this in the loop (or any place you'd like - as long as you have an ID to feed it..)
//First argument is the ID..
//Second argument is the size.. It'll handle 'large', 'medium', 'thumbnail' or even
'array(100, 100)'..
get_primary_image(get_the_ID(), 'large');
?>
以上就是Wordpress 显示主题图片的实现代码的全部内容,希望可以帮助到您。感谢对蚂蚁资源网的支持。
(责任编辑:南贤俊)
版权声明:文章内容是蚂蚁资源网小编精心整合原创的,素材来源于互联网,如无意侵犯到您的权益,请联系网站客服核实版权信息,以便及时删除。