<?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 显示主题图片的实现代码》的一些看法。更多内容请查看本栏目更多内容!
这个举措咱们应用一个hook来完成: 复制代码代码如下:add_action('publish_post', 'fetch_images',999); 再...
提示用户以后主题需求的插件 很多主题都需求一些插件的支持,这时你就需求提示用户需求装置的插件,本文将教...
WordPress引人注目的其中一个最大要素就是围绕这个内容治理零碎而进行的开发也不尽其数。因为WordPress...
提醒:清算前请先备份数据库,以防出不测。 经理论发现,只需执行顺次执行上面5个语句,就能够清算的比拟洁...
老鹰主机,是咱们站长应用较多的美国主机商之一。有些时分,咱们可能习气国际的一些主机商和管制面板的建站...
wpslugtranslate插件引见: 经过该插件,能够让wordpress中文博客的博主应用/%postname%.html方式的固定链接...