<?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 显示主题图片的实现代码》的一些看法。更多内容请查看本栏目更多内容!
esc_url()(过滤链接) 很多 URL 会有一些小谬误,用 esc_url() 函数能够屏蔽或许修改这些谬误,并且能够回...
本文实例讲述了WordPress后盾地址被改招致无奈登陆后盾的简略处理办法。分享给大家供大家参考,详细如下: ...
最近钻研民间主题 Twenty Eleven ,有一些货色网上现成的中文材料不好找,在博客里记录上去,算是分享,也算...
comments_template comments_template 函数是一个调用评论模板的函数,应用起来很简略,与get_header()等函...
本文实例讲述了WordPress完成搜寻后果只有一篇文章时主动跳转到文章的办法。分享给大家供大家参考。详细剖析...
wp_parse_args() 函数是 WordPress 外围常常用到的函数,它的用处很多,但最次要用来给一个数组参数(args)...