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中应用wp-cron插件来设置定时义务

PHP 自身是无奈创立定时义务的,然而 WordPress 自带了一个伪定时义务(Cron) API,十分的不便好用,包括 ...

WordPress查问某年某月文章的SQL语句

利用$wpdb自定义查问能够调用某年下的月份归档, 例如调用2014年月份归档的代码如下所示。复制代码代码如下:...

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

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

WordPress中给文章增加自定义字段及后盾编辑性能区域

add_post_meta add_post_meta 函数是 WordPress 中用来给文章或页面增加自定义字段值的一个函数, 其用法与...

Wordpress固定链接伪动态的设置办法

明天,想着在我机器上测试一下wordpress,尽管之前也有这个开源的顺序,可是不断没有装置呢,再加上最近不断...

WordPress中is_singular()函数简介

函数is_singular()检测后果为true,当上面其一前往true时:is_single()、is_page()、is_attachment()。 假如...

需求提交

客服服务