<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
> <channel><title>博优谷 &#187; get the image</title> <atom:link href="http://www.canfree.com/tag/get-the-image/feed" rel="self" type="application/rss+xml" /><link>http://www.canfree.com</link> <description>博优谷是知名的IT评论博客，探讨网站优化，网上赚钱，免费资源，站长工具，站长新闻等资讯</description> <lastBuildDate>Sun, 05 Feb 2012 15:46:40 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.2.1</generator> <item><title>不用插件实现日志缩略图功能</title><link>http://www.canfree.com/thumbnail-plug-ins-do-not-achieve-the-function-of-the-log.htm</link> <comments>http://www.canfree.com/thumbnail-plug-ins-do-not-achieve-the-function-of-the-log.htm#comments</comments> <pubDate>Mon, 11 Jan 2010 17:48:30 +0000</pubDate> <dc:creator>博优谷</dc:creator> <category><![CDATA[主题优化]]></category> <category><![CDATA[get the image]]></category> <category><![CDATA[WordPress]]></category> <category><![CDATA[代码]]></category> <category><![CDATA[技巧]]></category> <category><![CDATA[缩略图]]></category> <guid
isPermaLink="false">http://www.canfree.com/thumbnail-plug-ins-do-not-achieve-the-function-of-the-log.htm</guid> <description><![CDATA[在1月10号的时候本站介绍过日志缩略图插件Get The Image，可以很方便的在首页或其它页面输出文章缩略图，返回首页即可看到实际效果。 但是今天在幸福的收藏夹那里看到了一段代码，可以实现这种效果，特做个记号，以备急需时使用。 &#60;?php $soContent = $post-&#62;post_content; $soImages = '~&#60;img [^\&#62;]*\ /&#62;~'; preg_match_all( $soImages, $soContent, $thePics ); $allPics = count($thePics[0]); switch ( $allPics &#62; 0 ) { case $allPics = 1: echo $thePics[0][0]; // 显示文章中的第一张图片 break; // 当图片数量有1个时，不再执行 default: echo &#34;图片地址&#34;; // 这里加入没图片时显示的默认图片 }; ?&#62; 将上面的代码放到index.php文件中合适位置，再配上CSS定义样式即可。本站并未测试此代码的有效性，有空时再说。 引申阅读：wordpress首页分类图片调用 为你的每一个分类目录指定一个图片，并按照文章所属的分类在首页以缩略图的形式展示出来。]]></description> <content:encoded><![CDATA[<p>在1月10号的时候本站介绍过<a
href="http://www.canfree.com/log-thumbnail-plug-in-get-the-image-detailed-description-of.htm">日志缩略图插件Get The Image</a>，可以很方便的在首页或其它页面输出文章缩略图，返回首页即可看到实际效果。</p><p>但是今天在<a
href="http://www.happinesz.cn/archives/935/">幸福的收藏夹</a>那里看到了一段代码，可以实现这种效果，特做个记号，以备急需时使用。</p><div><pre>&lt;?php
$soContent = $post-&gt;post_content;
$soImages = '~&lt;img [^\&gt;]*\ /&gt;~';
preg_match_all( $soImages, $soContent, $thePics );
$allPics = count($thePics[0]);
<span style="color: #0000ff">switch</span> ( $allPics &gt; 0 ) {
<span style="color: #0000ff">case</span> $allPics = 1:
echo $thePics[0][0]; <span style="color: #008000">// 显示文章中的第一张图片</span>
<span style="color: #0000ff">break</span>; <span style="color: #008000">// 当图片数量有1个时，不再执行</span>
<span style="color: #0000ff">default</span>:
echo &quot;<span style="color: #8b0000">图片地址</span>&quot;; <span style="color: #008000">// 这里加入没图片时显示的默认图片</span>
};
?&gt;</pre></div><p>将上面的代码放到index.php文件中合适位置，再配上CSS定义样式即可。本站并未测试此代码的有效性，有空时再说。</p><p>引申阅读：<a
href="http://www.canfree.com/wordpress-home-categories-photo-call.htm">wordpress首页分类图片调用</a> 为你的每一个分类目录指定一个图片，并按照文章所属的分类在首页以缩略图的形式展示出来。</p> ]]></content:encoded> <wfw:commentRss>http://www.canfree.com/thumbnail-plug-ins-do-not-achieve-the-function-of-the-log.htm/feed</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>日志缩略图插件Get The Image详细说明</title><link>http://www.canfree.com/log-thumbnail-plug-in-get-the-image-detailed-description-of.htm</link> <comments>http://www.canfree.com/log-thumbnail-plug-in-get-the-image-detailed-description-of.htm#comments</comments> <pubDate>Sat, 09 Jan 2010 16:12:04 +0000</pubDate> <dc:creator>博优谷</dc:creator> <category><![CDATA[站长资讯]]></category> <category><![CDATA[get the image]]></category> <category><![CDATA[WordPress]]></category> <category><![CDATA[代码]]></category> <category><![CDATA[插件优化]]></category> <guid
isPermaLink="false">http://www.canfree.com/log-thumbnail-plug-in-get-the-image-detailed-description-of.htm</guid> <description><![CDATA[之前写一篇wordpress首页分类图片调用，今天决定停用并去掉相关的代码。换成Get The Image，这是我见过的最轻量级缩略图插件，可以后台搜索安装。使用时将相关代码拷贝到index.php中的&#60;?php the_content前面即可。 激活后，只能到插件-编辑-选择get the image中的get-the-image.php进行进行编辑，这样也好，一个文件就搞定了一切。 你看到的代码跟我下面贴出的有些出入，问题不大，正好你可以通过本站直接看到效果： &#160; function get_the_image( $args = array() ) { global $post; /* Set the default arguments. */ $defaults = array( 'custom_key' =&#62; array( 'Thumbnail', 'thumbnail' ), 'post_id' =&#62; $post-&#62;ID, 'attachment' =&#62; true, 'the_post_thumbnail' =&#62; true, // WP 2.9+ image function 'default_size' =&#62; 'thumbnail', 'default_image' =&#62; true, 'order_of_image' =&#62; [...]]]></description> <content:encoded><![CDATA[<p> 之前写一篇<a
href="http://www.canfree.com/wordpress-home-categories-photo-call.htm" target="_blank">wordpress首页分类图片调用</a>，今天决定停用并去掉相关的代码。换成<a
href="http://justintadlock.com/archives/2008/05/27/get-the-image-wordpress-plugin" target="_blank"><strong>Get The Image</strong></a><strong>，</strong>这是我见过的最轻量级缩略图插件，可以后台搜索安装。使用时将相关代码拷贝到index.php中的&lt;?php the_content前面即可。</p><p>激活后，只能到插件-编辑-选择get the image中的<strong>get-the-image.php</strong>进行进行编辑，这样也好，一个文件就搞定了一切。</p><p>你看到的代码跟我下面贴出的有些出入，问题不大，正好你可以通过本站直接看到效果：</p><p> <span
id="more-168"></span><p>&#160;</p><div><pre><span style="color: #800000">function</span> <span style="color: #800000">get</span>_<span style="color: #800000">the</span>_<span style="color: #800000">image</span>( $<span style="color: #800000">args</span> = <span style="color: #800000">array</span>() ) {
	<span style="color: #ff0000">global</span> <span style="color: #0000ff">$post</span>;
	<span style="color: #008000">/* Set the default arguments. */</span>
	$<span style="color: #ff0000">defaults</span> <span style="color: #0000ff">= array(
		'custom_key' =&gt; array( 'Thumbnail', 'thumbnail' ),
		'post_id' =&gt; $post-&gt;ID,
		'attachment' =&gt; true,
		'the_post_thumbnail' =&gt; true, // WP 2.9+ image function
		'default_size' =&gt; 'thumbnail',
		'default_image' =&gt; true,
		'order_of_image' =&gt; 1,
		'link_to_post' =&gt; true,
		'image_class' =&gt; false,
		'image_scan' =&gt; false,
		'width' =&gt; 70,
		'height' =&gt; 70,
		'format' =&gt; 'img',
		'echo' =&gt; true
	)</span>;</pre></div><p></p><ul><li><strong>custom_key</strong>,自定义值，如果你是在WP后台写作的话，那么就需要在自定义域中加上thumbnail，再配上一个图片地址（外链、内链图都可以）就可以了；如果你是live write写作的话，这个就不用理会它。</li><li><strong>default_image</strong>为true时，当你文章中没有图片就调用一个指定的图片代替。为false时，若文中无图，将什么都不显示。</li><li><strong>order_of_image</strong>值为1时表示抓取文中第一个图片。</li><li><strong>width与height</strong>是缩略图的宽和高，可自行控制。</li></ul><p>其它参数保持默认，无须更改。下面两种代码可满足多数需要，更高级的参考官方说明。</p><p><strong>通过WP后台写作，需要用下面的代码</strong></p><div><pre><span style="color: #0000ff">&lt;?</span>php get_the_image( <a style="color: #ffa500" href="http://www.php.net/array">array</a>( '<span style="color: #8b0000">custom_key</span>' =&gt; <a style="color: #ffa500" href="http://www.php.net/array">array</a>( '<span style="color: #8b0000">Thumbnail</span>', '<span style="color: #8b0000">thumbnail</span>' ), '<span style="color: #8b0000">default_size</span>' =&gt; '<span style="color: #8b0000">thumbnail</span>' ) ); <span style="color: #0000ff">?&gt;</span></pre></div><p><strong>通过live write写作的话，用下面的代码</strong></p><div><pre><span style="color: #0000ff">&lt;?</span>php get_the_image( <a style="color: #ffa500" href="http://www.php.net/array">array</a>( '<span style="color: #8b0000">default_image</span>' =&gt; '<span style="color: #8b0000">http://mysite.com/wp-content/uploads/example.jpg</span>' ) ); <span style="color: #0000ff">?&gt;</span></pre></div><p>本站添加的即是第2种代码，可确保文中无图片时能显示默认的缩略图。将图片链接更改为你自己的杰克。</p><p><strong>如果你想在分类页面、存档页面、搜索结果页面都显示缩略图，也只需要将代码拷贝到相应位置即可。</strong></p><p>你还可以自己定义一个CSS样式，对缩略图进行控制。</p><p>使用此插件，左手烟@特地测试了一下页面加载速度，相差仅在毫秒间，强烈推荐。</p> ]]></content:encoded> <wfw:commentRss>http://www.canfree.com/log-thumbnail-plug-in-get-the-image-detailed-description-of.htm/feed</wfw:commentRss> <slash:comments>7</slash:comments> </item> </channel> </rss>
