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中设置Post Type自定义文章类型的实例教程

什么是自定义post&#63; 不要想当然的以为这里的post就是就是指博客中的文章,它只不过是一个文章类的代理词...

WordPress中登陆后封闭登陆页面及设置用户不可见栏目

用户登录后封闭登录页面 WordPress默许的登录页面是:http://WP目录/wp-login.php,登录后会主动跳转到:ht...

在wordpress可视化编辑器中输出带缩进的代码

在WordPress中,咱们发如今写文章时,可视化模式下会对html代码进行清算,例如对<>等符号转化为html实体,对...

深化解析WordPress中加载模板的get_template_part函数

最近钻研民间主题 Twenty Eleven ,有一些货色网上现成的中文材料不好找,在博客里记录上去,算是分享,也算...

wordpress获取某个栏目链接地址的办法

wordpress获取某个分类的链接地址的两种办法: 经过get_category_link() 获取分类文章的链接URL,参数为文章...

晋升WordPress 关上速度片面处理计划

从ThemeForest购买的是正版商业主题AVADA(有售后技术支持),应用国际阿里云主机(配置不算低),网站大局...

需求提交

客服服务

亿鸽在线客服系统