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中的shortcode短代码性能应用详解

WordPress 从 2.5 的版本开端,添加了一个 shortcode (短代码) API ,相似于 BBS 上的 BBCode , shortcode ...

WordPress首页显示多个图片及文字友谊链接的办法

本文实例讲述了WordPress首页显示多个图片及文字友谊链接的办法。分享给大家供大家参考。详细剖析如下: Wo...

详解WordPress开发中过滤属性以及Sql语句的函数应用

esc_attr()(过滤属性) 普通在写 Html 代码的标签属性的时分会是下边的格局: <input type="text" name="...

WordPress 完成文章评论排行榜

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

WordPress菜单CSS类选项设置办法

WordPress菜单CSS类选项设置办法: 1、点开WordPress菜单设置页面右上角&ldquo;显示选项&rdquo;,勾选外面的...

优化WordPress分类链接及WP-No-Category-Base的卸载办法

默许状况下,WordPress分类的永世链接是这样的比方本站的技术文章分类。 exehack.net/category/my-article/...

需求提交

客服服务

亿鸽在线客服系统