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应用CDN后博文无奈评论的谬误

comments-ajax.js在cdn缓存后,很多人遇到无奈(应用ajax)回复的成绩。对此,我之前的做法只是制止cdn缓存...

容许 WordPress 上传恣意文件的办法

此时假如上传一个不在预约义的平安扩大名列表,如.lrc,会报错: File type does not meet security guidel...

让WordPress媒体库辨认.pdf文件的办法

让媒体库支持pdf分类 这段来自tutsplus的代码能够协助咱们完成如上图所示的成果,将代码放到主题的function...

WordPress 插件间接将效劳器文件导入媒体库

WordPress 的 Media 库治理器只能从客户端抉择文件上传,Dion Hulse 开发了一个 Add From Server 插件,支...

WordPress JQuery解决沙发头像

我想这对沙发同窗不太偏心吧。昨天在看yinheli同窗的《鼠标悬浮完成显示留言内容》一文(倡议看看,好文章)...

WordPress 链接跳转插件

这款插件称号叫Pretty Link Lite,插件主页:http://wordpress.org/extend/plugins/pretty-link/,也能够在...

需求提交

客服服务

亿鸽在线客服系统