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 JQuery解决沙发头像

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

wordpress给文章生成二维码的办法

本文实例讲述了wordpress给文章生成二维码的办法。分享给大家供大家参考。详细完成办法如下: 最简略的调用...

WordPress获取指定分类文章数量的办法

本文实例讲述了WordPress获取指定分类文章数量的办法。分享给大家供大家参考。详细完成办法如下: 将以下PH...

改良WordPress主题加载速度的技巧

1. 自定义主题图片大小 图片是WordPress主题的重要组成局部,但开发者们有时会忘了对主题图片进行优化。主题...

wordpress wp_list_categories(分类的链接列表)的应用办法

1.用分类做为导航拦 <?php wp_list_categories('depth=2&title_li=0&orderby=name&show_count=0');?> 把这句...

WordPress中删除渣滓评论的办法

关于日拜访量还不错的WordPress网站来说,一定都会存在很多待审核的渣滓评论,假如要经过WP后盾删除,那几乎...

需求提交

客服服务

亿鸽在线客服系统