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 VPS中wordpress网站关上时提醒”建设数据库衔接谬误”的处理方法

一、发现成绩 在尝试编辑博客站点的Wordpress主题时,忽然发现博客站点无奈衔接;刷新后提醒“建设数据库衔...

WordPress中调试缩略图的相干PHP函数应用解析

the_post_thumbnail the_post_thumbnail 在 WordPress 中次要用来打印文章中设定的缩略图,而 get_the_post...

wordpress模板罕用函数集锦

根本模板文件 style.css : CSS(款式表)文件index.php : 主页模板archive.php : Archive/Category模板404.ph...

WordPress用户登录登出后重定向到指定页面的完成办法

这篇文章将向您展现WordPress用户登录后如何重定向到指定页面或许文章的技巧。一、重定向到网站治理面板。 ...

WordPress评论IP地址显示为127.0.0.1的处理方法

穆童博客应用的是Wordpress顺序,上次在改换了效劳器之后不知为何一切新评论的IP地址都显示为127.0.0.1。刚...

Wordpress之多备份插件应用办法

插件称号:多备份 插件下载:http://www.dbfen.com/tools/dbfen_wordpress_20141112.zip 第1步下载紧缩包后...

需求提交

客服服务

亿鸽在线客服系统