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登录页的一些技巧办法

下文提到的一切代码,都是增加到主题的funshions.php 文件的最初一个 ?> 的后面。 制造一个名为 login_logo...

WordPress 的次要特点

要害字形容:特点 次要 WordPress 能够 链接 公布 文章 博客 进行 WordPress 的次要特点。WordPress 有很多...

wordpress自定义上传文件类型的办法

前言 家喻户晓WordPress默许支持大局部图片等文件格局的上传,但也有一些文件格局是不支持的,依据集体需求...

详解WordPress开发中get_header()获取头部函数的用法

函数意义详解 从以后主题调用header.php文件。是不是很简略?好吧,假如你是老手的话这里要提示一下,这里的...

处理WordPress应用CDN后博文无奈评论的谬误

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

调试WordPress中定时义务的相干PHP脚本示例

普通人们应用WordPress的Cron API来完成定时义务,它的原理就是将创立的定时义务存储到数据库里,当有人拜访...

需求提交

客服服务

亿鸽在线客服系统