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的Google字体以减速国际效劳器上的运转

因为Google被彻底墙掉,不翻墙就无奈加载谷歌字体。很多老手冤家常常埋怨本人买的主机如何如何慢,给的示例...

WordPress 标签Tags页面制造办法

p.s.在搜寻引擎优化SEO上,百度仿佛对要害词TAGS更为偏爱 其实就是撰写一个新页面,它要使用一个名为tags.php...

把WordPress文章版权同时在注释下方和Feed中输入完成办法

此前,咱们只晓得给WordPress文章增加版权申明,文章标签、相干日志,但很少思考到把这些信息输入到Feed中。...

WordPress别名已被其它条目应用的处理办法

最近我心血来潮给博客建一个分类别名为&ldquo;WordPress&rdquo;的目录。可是不断提醒&ldquo;别名已被其它条...

wordpress非插件完成增加链接转跳性能

链接方式http://localhost/?go=http://www.baidu.com这种方式转跳的办法。 复制代码代码如下:add_action('w...

WordPress站点完成分类目录订阅性能实例

WordPress有着比拟弱小的分类机制,包括文章分类、标签等,弱小的分类机制能够用来完成门户网站的相似二级频...

需求提交

客服服务

亿鸽在线客服系统