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菜单CSS类选项设置办法

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

详解WordPress中用于分解数组的wp_parse_args()函数

wp_parse_args() 函数是 WordPress 外围常常用到的函数,它的用处很多,但最次要用来给一个数组参数(args)...

在WordPress中应用PHP脚原本判别访客来自什么国度

区分访客国度有什么用&#63; 这里是几个我利用该性能的例子. 1.区分网站性能 这个博客有翻译文章的性能, 这是...

Wordpress自定义字段的应用心得

要害字形容:心得 应用 定义 &nbsp 能够 &lt &quot php &gt 一个 一些 应用Wordpress曾经有一段工夫...

WordPress插件开发设计

  WordPress引人注目的其中一个最大要素就是围绕这个内容治理零碎而进行的开发也不尽其数。因为WordPress...

详解WordPress中提示装置插件以及暗藏插件的性能完成

提示用户以后主题需求的插件 很多主题都需求一些插件的支持,这时你就需求提示用户需求装置的插件,本文将教...

需求提交

客服服务

亿鸽在线客服系统