加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > CMS系统 > wordpress > 正文

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

发布时间:2020-12-14 14:45:13 所属栏目: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

<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'); ?>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读