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呈现&ldquo;需求晋级数据库&rdquo;普通是网站搬家,或许WordPress版本晋级会呈现。普通状况呈现的...

wordpress正当利用wp-config.php文件小性能

这里有几个经过往wp-config.php中增加代码完成相干性能的技巧分享给大家。 1,去掉WordPress的历史修订版本...

WordPress中发送HTML邮件的办法

办法一,用filter发送HTML邮件 发邮件用的函数是wp_mail(),wp_mail()则基于弱小的邮件类phpMailer,所以发...

WordPress中登陆后封闭登陆页面及设置用户不可见栏目

用户登录后封闭登录页面 WordPress默许的登录页面是:http://WP目录/wp-login.php,登录后会主动跳转到:ht...

推荐十款收费 WordPress 插件

2015必备wordpress插件列表。为了加强wordpress站点,一些优秀无效的收费wordpress 插件是必不可少的。 Wo...

在WordPress中应用wp_count_posts函数来统计文章数量

做一个全站统计是不是很酷?短暂的博客越来越少,何不给本人的一个统计,看看本人在这个博客上致力了多少,...

需求提交

客服服务

亿鸽在线客服系统