<?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 显示主题图片的实现代码》的一些看法。更多内容请查看本栏目更多内容!
(如下图),民间的称号叫admin bar,中文咱们就把它叫做治理工具栏吧,也有称之为治理工具条、快捷链接栏的...
WordPress 自身以及主题和插件通常需求加载一些 JavaScript 来完成某些非凡性能。为了最大限制地保障兼容性...
WordPress应用MySQL数据库。作为一个开发者,咱们有必要把握WordPress数据库的根本结构,并在本人的插件或主...
esc_html()(本义 Html) esc_html() 函数用来本义 Html 代码,让 Html 代码不本义。 用法 esc_html( $tex...
间接上代码吧 复制代码代码如下:<title><?phpif(is_category()){ single_cat_title();}elseif(is_single() ...
WordPress呈现“需求晋级数据库”普通是网站搬家,或许WordPress版本晋级会呈现。普通状况呈现的...