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 主题图片
版权声明:本文为 安达网络工作室 转载文章,如有侵权请联系我们及时删除。
相关文章
WordPress数据库的根本结构及各表构造

WordPress应用MySQL数据库。作为一个开发者,咱们有必要把握WordPress数据库的根本结构,并在本人的插件或主...

WordPress获取以后页面URL地址的办法

本文实例讲述了WordPress获取以后页面URL地址的办法。分享给大家供大家参考。详细如下: 咱们常常在做WordP...

wordpress编辑器中增加链接性能主动退出nofollow的办法

由于偶然加一些站外链接,普通都是nofollow,独自写入很费事,所以揣摩从编辑器动手,经过这个插件(http:/...

编写PHP脚本肃清WordPress头部冗余代码的办法解说

wordpress头部的代码十分多,包括WordPress版本,前后文、第一篇文章、主页meta信息等各种冗余代码,这些对...

WordPress 3.0 十大看点 CMS性能进一步加强

1. 自定义用户名和明码 新版本一开端就会给用户惊喜! 目前咱们装置WordPress之后,零碎会给咱们一个用户ad...

WordPress开发中的get_post_custom()函数应用解析

同get_post_meta()一样,用于前往文章的自定义字段值得一个函数,只不过get_post_custom()函数应用起来更简...

需求提交

客服服务

亿鸽在线客服系统