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');

?>



相关阅读:
javaScript事件使用方法
CSS经典技巧20条总结
Vista组策略实现对指定分区的隐藏和限制
ISA S和Exchange S装在同一win2k s上.如何才能向internet发布
Linux 中动态重新配置和调整介绍
用asp实现的截取指定格式字符串的代码
详细讲解JS节点知识
SQLserver 实现分组统计查询(按月、小时分组)
在web上管理MySQL:phpMyAdmin使用讲解
“疯狂的企鹅” 看Linux安全的未来
PHP与javascript对多项选择的处理
如何在Jsp中使用JDBC来联结MySql
CSS制作具亲和力的表格
自定义容器和字体大小
快速导航

Copyright © 2016 phpStudy | 皖ICP备18014864号-4