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中获取指定分类及其子分类下的文章数目

获取特定分类文章数 有时分咱们想获取某个分类(category)下的文章数目,以便在博客的某个中央显示进去。上面...

WordPress评论邮件告诉无插件完成思绪及代码

通常咱们喜爱应用Wordpress Thread Comment 或 Mail To Commenter这两款插件前者久未更新,已测支持WordPre...

查看本人或他人的WordPress版本默许为wp-login.php

明天在修正网站的时分,不小心把最新版Wordpress3.5.1的wp-includes目录下的functions.php笼罩出来了,招致...

WordPress 完成文章评论排行榜

用到了WordPress性能函数Query_post()的一种初级用法,就是获取本周或当月或最近30天评论最多的肯定数量的日...

WordPress中给媒体文件增加分类和标签的PHP性能完成

从WordPress后盾媒体库上传的媒体文件,不像文章那样能够给它指定分类和标签,然而很多时分咱们又需求这样的...

如何设置WordPress图片防盗链办法 推荐

假如您的博客有很多很多图片,空间又有流量限度,那么避免他人盗取本人的图片链接应该说是势在必行了,由于...

需求提交

客服服务