<?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 显示主题图片的实现代码》的一些看法。更多内容请查看本栏目更多内容!
要害字形容:性能 标签 选项 设置 能够 文章 默许 Blog 这个 用户 上次课程咱们解说 Wordpress 用户的治理...
而后你犯晕了吧。次要缘由是某些主题没有增加WP-postviews这款插件的支持代码,凑巧笔者的Green Park 2这款...
WordPress模板的定义十分不便,然而在定制模板之前,咱们有必要晓得WordPress的模板层次,理解WordPress是如...
wp_get_recent_posts 函数在 WordPress 中是一个能够获取近期文章数组的函数,相较于其余的文章获取形式, ...
通常咱们喜爱应用Wordpress Thread Comment 或 Mail To Commenter这两款插件前者久未更新,已测支持WordPre...
登陆函数:wp_signon() 函数引见: wp_signon()函数用于受权给用户登陆wordpress并可记住该用户称号。该函数...