<?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 显示主题图片的实现代码》的一些看法。更多内容请查看本栏目更多内容!
以下代码来自网络,未经测试,操作数据库有危险,请事前备份 !为一切文章和页面增加自定义字段 这段代码能...
插件称号:多备份 插件下载:http://www.dbfen.com/tools/dbfen_wordpress_20141112.zip 第1步下载紧缩包后...
p.s.在搜寻引擎优化SEO上,百度仿佛对要害词TAGS更为偏爱 其实就是撰写一个新页面,它要使用一个名为tags.php...
下文提到的一切代码,都是增加到主题的funshions.php 文件的最初一个 ?> 的后面。 制造一个名为 login_logo...
本文实例讲述了Wordpress完成文章支持和拥护性能的办法。分享给大家供大家参考。详细剖析如下: 假如你上网...
首先,你要在wp-content/plugins/下建设一个文件夹,文件夹的名字最好只由字母、数字、“-”和下...