手机
当前位置:查字典教程网 >CMS教程 >WordPress >Wordpress 显示主题图片的实现代码
Wordpress 显示主题图片的实现代码
摘要:

<?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 显示主题图片的实现代码】相关文章:

WordPress 文章摘要功能实现代码

wordpress上传图片不自动生成缩略图的解决方法

改进WordPress主题加载速度的技巧

WordPress最好用的博客系统之一

WordPress 实现文章评论排行榜

IIS6.0下Wordpress 去掉 index.php 和 category 的方法小结

wordpress自定义摘要截取字数的代码

WordPress虚拟主机的选择

WordPress中函数get_term_link的参数设置问题

wordpress 为主题添加AJAX提交评论功能的php代码

精品推荐
分类导航