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应用CDN后博文无奈评论的谬误

comments-ajax.js在cdn缓存后,很多人遇到无奈(应用ajax)回复的成绩。对此,我之前的做法只是制止cdn缓存...

WordPress中编写自定义存储字段的相干PHP函数解析

WordPress 的自定义字段就是文章的 meta 信息(元信息),利用这个性能,能够扩大文章的性能,是学习 WordP...

如何在本地装置Wordpress

要害字形容:装置 本地 如何 Wordpress 下载 应用 环境 // 版本 Windows 上一次教程将 wordpress如何装置,...

WordPress中查问文章的循环Loop构造及用法剖析

WordPress 上获取文章最重要的就是循环(Loop),现实上循环就是去数据库查问到相应的文章,而后临时贮存到...

Wordpress不必插件的SEO优化办法分享

复制代码代码如下:<title><?php if ( is_home() ) { ?><?php bloginfo('name'); ?> | <?php bloginfo('...

详解WordPress开发中的get_post与get_posts函数应用

get_post() 在普通主题制造时,get_post()函数咱们普通很少会用到,但由于前面会讲到get_posts(),所以咱们...

需求提交

客服服务

亿鸽在线客服系统