2014年8月25日
用七牛云插件提供的wpjam_post_thumbnail实现Ribbon主题自动获取缩略图
小站初建立时,曾尝试自动获取缩略图,但严重受挫,失败经历可以围观吾之漫漫建站路(二)_云存储的抉择。迄今为止,小站每篇文章的缩略图都是先将图片上传至主机空间,然后再通过wordpress自带的缩略图功能来对缩略图进行设置,让各位大拿见笑了。
其实我自己也觉得很烦,所以暗自努力,终于通过修改代码实现了在不改变现有文章缩略图的前提下自动获取缩略图,在本地主机中验证完成。
小站的Ribbon主题中用到缩略图的文件有index.php,archive.php,widget-tabs.php,其中index/archive文件各需修改一处,它们的修改方式一致;widget-tabs需要修改两处,修改方式一致。
1.index/archive文件中的修改方式
ribbon主题中原来的代码:
1 2 3 4 5 |
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>" rel="nofollow" id="featured-thumbnail"> <?php if ( has_post_thumbnail() ) { ?> <?php echo '<div class="featured-thumbnail">'; the_post_thumbnail('featured',array('title' => '')); echo '</div>'; ?> <?php } ?> </a> |
修改后的代码:
1 2 3 4 5 6 7 8 |
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>" rel="nofollow" id="featured-thumbnail"> <div class="featured-thumbnail"> <?php if(wpjam_has_post_thumbnail()) { wpjam_post_thumbnail(array(150,150),$crop=1); } ?> </div> </a> |
2.widget-tabs的修改方式
ribbon主题中原来的代码:
1 2 3 4 5 6 |
<?php if(has_post_thumbnail()): ?> <?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'recent_post_thumb'); ?> <a href='<?php the_permalink(); ?>'><img src="<?php echo $image[0]; ?>" alt="<?php the_title(); ?>" width='65' height='50' class="wp-post-image" /></a> <?php else: ?> <a href='<?php the_permalink(); ?>'><img src="<?php echo get_template_directory_uri(); ?>/images/smallthumb.png" alt="<?php the_title(); ?>" width='65' height='50' class="wp-post-image" /></a> <?php endif; ?> |
修改后的代码:
1 2 3 4 5 |
<?php if(wpjam_has_post_thumbnail()): ?> <a href='<?php the_permalink(); ?>'> <?php wpjam_post_thumbnail(array(65,50), $crop=1);?></a> <?php else: ?> <a href='<?php the_permalink(); ?>'><img src="<?php echo get_template_directory_uri(); ?>/images/smallthumb.png" alt="<?php the_title(); ?>" width='65' height='50' class="wp-post-image" /></a> <?php endif; ?> |
边栏最近访客这个插件共享下:)
你好,边栏最近访客是多说提供的小工具,安装了多说就有的
。