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博客效劳器环境配置

早就想搭建一个专属于本人的博客了,用来记载本人生存、学习的点点滴滴。之所以选WordPress,次要是由于它能...

WordPress中用于检索模版的相干PHP函数应用解析

locate_template() 用来检索存在的优先级最高的模板文件,还能间接加载模板文件。 locate_template() 函数检...

七牛镜像存储 WordPress 插件(一键完成 WordPress 博客动态文件 CDN减速)

七牛云存储是由七牛提供的在线存储效劳,经过云端接口向企业客户提供网上有限存储空间,和传统的云存储效劳...

wordpress在装置应用中呈现404、403、500及502成绩的剖析与处理办法

前言 最近在应用WordPress的时分遇到了一些谬误提醒,置信大家在应用wordpress建设网站的时分,都会遇到一些...

WordPress 模板制造进程中的谬误定位办法

在wordpress模板制造进程中,有一些貌似复杂的成绩,其实只需确定了成绩呈现的地位,大少数都能够自行处理。...

完满处理wordpress sae版改域名后不能进入后盾的成绩

处理方法: 办法一: 修正文件&ldquo;/wp-includes/pluggable.php&rdquo;中的wp_set_auth_cookie函数。搜寻...

需求提交

客服服务

亿鸽在线客服系统