微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Wordpress 显示主题图片的实现代码

<div class="msgborder" id="PHPcode15"> <?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,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'); ?>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐