首页 » Wordpress » Freshblog主题下的缩略图简化

Freshblog主题下的缩略图简化

5324 0

本站博客使用的Freshblog主题,缩略图部分一直没有修改过,每次在自定义字段内输入分类的图片链接地址,感觉还是有点不方便。今天在搞公司的网站的同时,正好闲暇之余,小改了一下,这样以后在自定义字段内不需要再输入http://www.tiandiyoyo.com/wp-content/uploads/2011/08/winXP.jpg这么长的URL了,而只要输入预先设计好的简称xp即可。

打开functions.php,修改代码为:

# Get image attachment (sizes: thumbnail, medium, full)
function get_thumbnail($postid=0, $size='full') {
	if ($postid<1) 
	$postid = get_the_ID();
	$thumb = get_post_meta($postid, "thumb", TRUE); // Declare the custom field for the image
	if ($thumb != null or $thumb != '') {    // 简化分类图
		if ($thumb == 'xp')              //添加简称xp
			echo "http://www.tiandiyoyo.com/wp-content/uploads/2011/08/winXP.jpg";
		else if ($thumb == 'mud')         //添加简称mud
			echo "http://www.tiandiyoyo.com/wp-content/uploads/2011/08/mud2.jpg";
		else if ($thumb == 'vb')           //添加简称vb
			echo "http://www.tiandiyoyo.com/wp-content/uploads/2011/08/vb.jpg";
		else if ($thumb == 'tools')        //添加简称tools
			echo "http://www.tiandiyoyo.com/wp-content/uploads/2011/08/tools.png";
		else if ($thumb == 'bbdev')           //添加简称bbdev
			echo "http://www.tiandiyoyo.com/wp-content/uploads/2011/08/blackberry-logo.jpg";
		else if ($thumb == 'bb')            //添加简称bb
			echo "http://www.tiandiyoyo.com/wp-content/uploads/2011/11/C3138W73OZ938G52JZG1FG3HIZU3JITE.jpg";
		else if ($thumb == 'wp')           //添加简称wp
			echo "http://www.tiandiyoyo.com/wp-content/uploads/2011/08/wordpress-plugins-600x300.jpg";
		else if ($thumb == 'java')             //添加简称java
			echo "http://www.tiandiyoyo.com/wp-content/uploads/2012/12/java.jpg";
		else               //其他
			echo $thumb; 
	}
	elseif ($images = get_children(array(
		'post_parent' => $postid,
		'post_type' => 'attachment',
		'numberposts' => '1',
		'post_mime_type' => 'image', )))
		foreach($images as $image) {
			$thumbnail=wp_get_attachment_image_src($image->ID, $size);
			?>
<?php echo $thumbnail[0]; ?>
<?php
		}
	else {
		echo get_bloginfo ( 'stylesheet_directory' );
		echo '/images/image-pending.gif';
	}
	
}
文章评分2次,平均分5.0

本文原始地址:https://www.tiandiyoyo.com/2013/02/freshblog-thumbnail/
本站所有文章,除了特别注明外,均为本站原创,转载请注明出处来自www.tiandiyoyo.com

您可能还会对以下文章感兴趣:

评论前先开启评论开关: