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 有人回复时邮件告诉的完成办法 SAE 移植版

1,先配置一下您的SMTP账户的用户名和明码。 2,将上面的内容粘贴到以后主题的 functions.php 中即可,留意...

WordPress中自定义后盾治理界面配色计划的小技巧

WordPress 3.8 开端的全新设计的后盾支持多颜色抉择,默许有八种十分精巧的配色,能够让用户本人抉择。 对...

将博客园(cnblogs.com)数据导入到wordpress的代码

我将这个分享进去,假如当前有谁需求能够间接下载上面插件 应用办法: 在cnblogs抉择备份数据,导出一个XML...

管制好你的 Wordpress 侧边栏

当然 Wordpress 2.7 里有&ldquo;小工具&rdquo;选项也能管制 Widget ,然而重复试验后发现款式无奈对立,可控...

WordPress文章题目链接增加正在加载中提醒的办法

本文实例讲述了WordPress文章题目链接增加正在加载中提醒的办法。分享给大家供大家参考。详细剖析如下: 咱...

the_time WordPress日期和工夫调用函数

复制代码代码如下: <?php the_time('Y-m-d'); ?> 显示的是 2011-10-1 这样的,修正()中内容用以下字符交换...

需求提交

客服服务

亿鸽在线客服系统