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 显示主题图片的实现代码》的一些看法。更多内容请查看本栏目更多内容!

本文相关话题: Wordpress 主题图片
版权声明:本文为 安达网络工作室 转载文章,如有侵权请联系我们及时删除。
相关文章
Dreamweaver代码的格局化性能掌控html代码的格局

明天偶尔发现了Dreamweaver的一个十分有用的性能,就是代码的格局化性能。普通状况下,咱们写的html或许css...

遗记wordpress的登录明码的处理办法(比拟简略)

起初在一站长的博客中看到了一个很简约的处理办法(当然不是重装啦,尽管也能够),就是把上面的代码写进一...

解析WordPress中的post_class与get_post_class函数

post_class() post_class 是 WordPress 内置的一个用于显示文章 class 称号的函数,该函数通常会为每一篇文...

wordpress在postname中支持大写字母的办法

普通而言,WordPress自身会对英语用户的体验进行优化,例如默许模板的分隔符永远都是&ldquo;|&rdquo;,由于...

几个优化WordPress中JavaScript加载体验的插件引见

WordPress 自身以及主题和插件通常需求加载一些 JavaScript 来完成某些非凡性能。为了最大限制地保障兼容性...

本人做wordpress评论插件修正评论款式(两步丑化评论内容)

wordpress自带的近期评论小工具不会显示详细的评论内容,而且还会显示治理员的评论,觉得不是很好,只能本人...

需求提交

客服服务

亿鸽在线客服系统