10
一
一
日志缩略图插件Get The Image详细说明
之前写一篇wordpress首页分类图片调用,今天决定停用并去掉相关的代码。换成Get The Image,这是我见过的最轻量级缩略图插件,可以后台搜索安装。使用时将相关代码拷贝到index.php中的<?php the_content前面即可。
激活后,只能到插件-编辑-选择get the image中的get-the-image.php进行进行编辑,这样也好,一个文件就搞定了一切。
你看到的代码跟我下面贴出的有些出入,问题不大,正好你可以通过本站直接看到效果:
function get_the_image( $args = array() ) { global $post; /* Set the default arguments. */ $defaults = array( 'custom_key' => array( 'Thumbnail', 'thumbnail' ), 'post_id' => $post->ID, 'attachment' => true, 'the_post_thumbnail' => true, // WP 2.9+ image function 'default_size' => 'thumbnail', 'default_image' => true, 'order_of_image' => 1, 'link_to_post' => true, 'image_class' => false, 'image_scan' => false, 'width' => 70, 'height' => 70, 'format' => 'img', 'echo' => true );
- custom_key,自定义值,如果你是在WP后台写作的话,那么就需要在自定义域中加上thumbnail,再配上一个图片地址(外链、内链图都可以)就可以了;如果你是live write写作的话,这个就不用理会它。
- default_image为true时,当你文章中没有图片就调用一个指定的图片代替。为false时,若文中无图,将什么都不显示。
- order_of_image值为1时表示抓取文中第一个图片。
- width与height是缩略图的宽和高,可自行控制。
其它参数保持默认,无须更改。下面两种代码可满足多数需要,更高级的参考官方说明。
通过WP后台写作,需要用下面的代码
<?php get_the_image( array( 'custom_key' => array( 'Thumbnail', 'thumbnail' ), 'default_size' => 'thumbnail' ) ); ?>
通过live write写作的话,用下面的代码
<?php get_the_image( array( 'default_image' => 'http://mysite.com/wp-content/uploads/example.jpg' ) ); ?>
本站添加的即是第2种代码,可确保文中无图片时能显示默认的缩略图。将图片链接更改为你自己的杰克。
如果你想在分类页面、存档页面、搜索结果页面都显示缩略图,也只需要将代码拷贝到相应位置即可。
你还可以自己定义一个CSS样式,对缩略图进行控制。
使用此插件,左手烟@特地测试了一下页面加载速度,相差仅在毫秒间,强烈推荐。
你咋不给个图片看看效果?
还有你怎么老是喜欢自己抢自己的沙发呀?
你回到首页不就看到效果了吗。右上角。
留言错误了。
好插件 我用了!!
有问题啊 我文章有图 还是现实默认的!!!!!
你好,我设置了这个插件的图片高宽都是150,结果缩略图反而都成了长方形。。。