<?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 显示主题图片的实现代码》的一些看法。更多内容请查看本栏目更多内容!
复制代码代码如下: function excerpt($limit) { $excerpt = explode(' ', get_the_excerpt(), $limit); i...
自从用了阿里云主机,真是没有省心过。 这两天网站CPU天天100+的,过一会就挂了,原来是wp-cron.php文件造成...
WordPress 的 Media 库治理器只能从客户端抉择文件上传,Dion Hulse 开发了一个 Add From Server 插件,支...
本文实例讲述了WordPress制止特定用户修正明码的办法。分享给大家供大家参考。详细办法如下: 有时咱们心愿...
很多WordPress站长都常常遭到渣滓评论的滋扰,针对这种状况,采纳上面的代码可能会对你有所协助。将以下代码...
本文实例讲述了WordPress获取文章内容摘要的办法。分享给大家供大家参考。详细如下: 第一个函数是讲述了能...