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 主题图片
版权声明:本文为 安达网络工作室 转载文章,如有侵权请联系我们及时删除。
相关文章
在Ubuntu 14.04上部署 PHP 环境及 WordPress

软件及版本抉择 Ubuntu 14.04 Ubuntu 是目前用户数量首屈一指的发行版,面前有大土豪保护,能够说是轻量级用...

如何将WordPress博客订阅到QQ邮箱详细该怎样操作

1、登录QQ邮箱,点击右下角&ldquo;浏览空间&rdquo;,进入浏览空间。 2、进入浏览空间后,点击页面右上角&ld...

Wordpress主动提取内容中第一张图片作缩略图的办法

本文实例讲述了Wordpress主动提取内容中第一张图片作缩略图的办法。分享给大家供大家参考。详细剖析如下: ...

wordpress评论者链接在新窗口中关上的办法

找到wp-includes/comment-template.php文件中 复制代码代码如下:if ( empty( $url ) || 'http://' == $url ...

在WordPress的后盾中增加顶级菜单和子菜单的函数详解

增加设置页面-add_menu_page函数 add_menu_page(),这个函数是往后盾增加顶级菜单先,也就是和“外观”、“...

WordPress CMS的劣势所在

现在,WordPress CMS 主题越来越多,WordPress 作为 CMS 终究有那些共同的劣势,吸援用户去一直的延长扩大呢...

需求提交

客服服务

亿鸽在线客服系统