<?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>Domety &#187; 摘要</title>
	<atom:link href="http://domety.com/archives/tag/%e6%91%98%e8%a6%81/feed/" rel="self" type="application/rss+xml" />
	<link>http://domety.com</link>
	<description>分享软件、互联网应用技巧以及开发技能</description>
	<lastBuildDate>Fri, 03 Feb 2012 14:02:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>the_content是如何输出摘要和全文的</title>
		<link>http://domety.com/archives/224/</link>
		<comments>http://domety.com/archives/224/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 14:27:46 +0000</pubDate>
		<dc:creator>DDBug</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[The Loop]]></category>
		<category><![CDATA[摘要]]></category>

		<guid isPermaLink="false">http://domety.com/?p=224</guid>
		<description><![CDATA[现在每次写文章的时候，已经习惯了在文章和第一段或前两段之后加一个more标签，这样首页的摘要就会显示more标签之前的内容。但是一直都有一个疑问，首页index.php和日志页面single.php都是调用the_content函数，为什么一个显示摘要，一个显示全文呢？
通过阅读wordpress的源代码，发现了这样一段代码
 if ( is_single() &#124;&#124; is_page() &#124;&#124; is_feed() )
  $more = 1;
难道是通过$more变量决定的？再去了解一下the_content的源代码，果然，就是通过$more变量来决定是输出摘要还是输出全文的。为了证实这个结论，我做了一个实验:
 修改index.php文件，在the_content之前强行把$more的值修改为1
$more = 1;
the_content();
结果之前一直显示摘要的首页，现在显示的是全文内容。同样，再去修改singel.php文件，在the_content之前强行把$more的值修改为0
$more = 0;
the_content();
结果日志页面显示的是摘要，而不是全文。
通过以上实验可以看出，the_content函数是输出全文还是输出摘要，是这个全局变量$more决定的。理解了这一点，我们就可以更灵活的运用the_content函数。下面通过一个实例来结束本文。
首页的第一篇文章显示全文，其它文章显示摘要：
&#60;?php if(have_posts() ){
                   $more = -1;
                   while(have_posts()){
                           the_post(); 
                           // ......
                          if($more == -1){
                                $more = 1;
                                the_content();
                                $more = 0;
                          } else {
                                the_content('继续阅读...');
                           }
                          // ......
                   }//end while(have_posts)
             }//end if(have_posts())
   else{
          echo '没有找到相关文章';
   }//end else
  ?&#62;
]]></description>
			<content:encoded><![CDATA[<p>现在每次写文章的时候，已经习惯了在文章和第一段或前两段之后加一个more标签，这样首页的摘要就会显示more标签之前的内容。但是一直都有一个疑问，首页index.php和日志页面single.php都是调用the_content函数，为什么一个显示摘要，一个显示全文呢？<span id="more-224"></span></p>
<p>通过阅读wordpress的源代码，发现了这样一段代码</p>
<pre name="code" class="php"> if ( is_single() || is_page() || is_feed() )
  $more = 1;</pre>
<p>难道是通过$more变量决定的？再去了解一下the_content的源代码，果然，就是通过$more变量来决定是输出摘要还是输出全文的。为了证实这个结论，我做了一个实验:</p>
<p> 修改index.php文件，在the_content之前强行把$more的值修改为1</p>
<pre name="code" class="php">$more = 1;
the_content();</pre>
<p>结果之前一直显示摘要的首页，现在显示的是全文内容。同样，再去修改singel.php文件，在the_content之前强行把$more的值修改为0</p>
<pre name="code" class="php">$more = 0;
the_content();</pre>
<p>结果日志页面显示的是摘要，而不是全文。</p>
<p>通过以上实验可以看出，the_content函数是输出全文还是输出摘要，是这个全局变量$more决定的。理解了这一点，我们就可以更灵活的运用the_content函数。下面通过一个实例来结束本文。</p>
<p>首页的第一篇文章显示全文，其它文章显示摘要：</p>
<pre name="code" class="php">&lt;?php if(have_posts() ){
                   $more = -1;
                   while(have_posts()){
                           the_post(); 
                           // ......
                          if($more == -1){
                                $more = 1;
                                the_content();
                                $more = 0;
                          } else {
                                the_content('继续阅读...');
                           }
                          // ......
                   }//end while(have_posts)
             }//end if(have_posts())
   else{
          echo '没有找到相关文章';
   }//end else
  ?&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://domety.com/archives/224/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>自定义more标签的more跳转</title>
		<link>http://domety.com/archives/220/</link>
		<comments>http://domety.com/archives/220/#comments</comments>
		<pubDate>Sun, 10 Jan 2010 14:35:17 +0000</pubDate>
		<dc:creator>DDBug</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[摘要]]></category>
		<category><![CDATA[正则表达式]]></category>

		<guid isPermaLink="false">http://domety.com/?p=220</guid>
		<description><![CDATA[很多主题首页的摘要都是使用the_content()函数来实现的，使用这种方法会在摘要结束的地方自动生成 一个more链接，比如&#8221;阅读更多&#8221;或&#8221;阅读全文&#8221;之类，当你点击这个链接之后会自动跳转到该日志页面摘要之后的部分。如果你喜欢这样的效果，那自然很好，不用修改。但是如果你不喜欢这种效果，而是想跳转到文章最开始的部分，那就继续向下看。
其实我们不难发现，more链接的链接地址就是在日志的链接地址之后加了一个#more-id，我们如果有办法把这个#more-id从链接中去掉不就行了吗？幸好wordpress给我们提供了一个叫做the_content_more_link的filter，通过它再加上正则表达式，可以很轻松的解决这个问题。

function remove_more_jump_link($link) {
return preg_replace('/#more-\d+/i','',$link);
}
add_filter('the_content_more_link', 'remove_more_jump_link');
把以上代码复制到functions.php文件即可。代码中的正则表达式也很好理解，就是把链接中#more-id形式的字符串替换为空。
]]></description>
			<content:encoded><![CDATA[<p>很多主题首页的摘要都是使用the_content()函数来实现的，使用这种方法会在摘要结束的地方自动生成 一个more链接，比如&#8221;阅读更多&#8221;或&#8221;阅读全文&#8221;之类，当你点击这个链接之后会自动跳转到该日志页面摘要之后的部分。如果你喜欢这样的效果，那自然很好，不用修改。但是如果你不喜欢这种效果，而是想跳转到文章最开始的部分，那就继续向下看。</p>
<p>其实我们不难发现，more链接的链接地址就是在日志的链接地址之后加了一个#more-id，我们如果有办法把这个#more-id从链接中去掉不就行了吗？幸好wordpress给我们提供了一个叫做the_content_more_link的filter，通过它再加上正则表达式，可以很轻松的解决这个问题。</p>
<pre name="code" class="php">
function remove_more_jump_link($link) {
return preg_replace('/#more-\d+/i','',$link);
}
add_filter('the_content_more_link', 'remove_more_jump_link');</pre>
<p>把以上代码复制到functions.php文件即可。代码中的正则表达式也很好理解，就是把链接中#more-id形式的字符串替换为空。</p>
]]></content:encoded>
			<wfw:commentRss>http://domety.com/archives/220/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>wordpress首页显示摘要的几种方法</title>
		<link>http://domety.com/archives/216/</link>
		<comments>http://domety.com/archives/216/#comments</comments>
		<pubDate>Sat, 09 Jan 2010 14:12:54 +0000</pubDate>
		<dc:creator>DDBug</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[摘要]]></category>

		<guid isPermaLink="false">http://domety.com/?p=216</guid>
		<description><![CDATA[大部分人的习惯都是在首页显示文章的摘要，本文总结了几种在首页显示摘要的方法。

more标签
这种方法应该是最灵活的一种方法，操作也很简单，只需要你在编辑文章的时候插入more标签

或者使用快捷键alt+shift+t，效果如下

那么如果你在主题的首页模板中调用the_content函数，首页的文章摘要就显示more之前的内容。相反，如果没有插入more标签，就会显示全文。
手动输入摘要
在首页模板中(比如home.php或index.php)中调用the_excerpt函数显示摘要，如果你在编辑文章的时候，在下面的“摘要”内输入了内容，则会显示该“摘要”里的内容

如果“摘要”里没有内容，就输出more标签前的内容，再如果没有more标签，就输出固定字数的摘要（这个固定的字数好像是默认的，很长，我还没找到更改这个字数的方法，有知道的希望告之）。
显示固定的字数
如果你的主机开通了php的mb_string扩展的话，可以使用mb_strimwidth函数来截取文章内容，以达到显示固定字数摘要的目的，比如首页摘要显示前200个字
echo mb_strimwidth(strip_tags($post-&#62;post_content),0,200,'......');
这样就会显示文章的前200个字，随后跟着一个省略号。这个mb_strimwidth函数可以很好截取中文字符。我们再稍改造一下，就可以显示“阅读全文”链接的效果
echo mb_strimwidth(strip_tags($post-&#62;post_content),0,200,'&#60;a href="'.get_permalink().'"&#62;......[阅读全文]&#60;/a&#62;');
但是，如果假如万一你的主机没有激活php的mb_string扩展，使用这个函数就会报错。在这种情况下，我们可以自定义一个类似的函数，下面是我写的一个截取utf-8字符串的函数dm_strimwidth，也是我正在使用的方法
function dm_strimwidth($str ,$start , $width ,$trimmarker ){
 $output = preg_replace('/^(?:[\x00-\x7F]&#124;[\xC0-\xFF][\x80-\xBF]+){0,'.$start.'}((?:[\x00-\x7F]&#124;[\xC0-\xFF][\x80-\xBF]+){0,'.$width.'}).*/s','\1',$str);
 return $output.$trimmarker;
}
使用方法和前面的mb_strimwidth是一样的，不过使用前你需要把上面的函数定义复制到functions.php文件中，然后调用
echo dm_strimwidth(strip_tags($post-&#62;post_content),0,200,'&#60;a href="'.get_permalink().'"&#62;......[阅读全文]&#60;/a&#62;');
综合方法
有时候下面这种做法也是不错的，即如果给文章手动添加了摘要，就显示这个手动添加的摘要，如果没有就显示固定的字数。方法如下：
if(has_excerpt()) the_excerpt();
 else
         echo mb_strimwidth(strip_tags($post-&#62;post_content),0,200,'&#60;a href="'.get_permalink().'"&#62;......[阅读全文]&#60;/a&#62;');
]]></description>
			<content:encoded><![CDATA[<p>大部分人的习惯都是在首页显示文章的摘要，本文总结了几种在首页显示摘要的方法。</p>
<p><span id="more-216"></span></p>
<h3>more标签</h3>
<p>这种方法应该是最灵活的一种方法，操作也很简单，只需要你在编辑文章的时候插入more标签</p>
<p><img class="alignnone" title="more标签" src="http://i623.domety.com/albums/tt312/baolai5/201001/wp_excerpt_001.png" alt="" width="508" height="92" /></p>
<p>或者使用快捷键alt+shift+t，效果如下</p>
<p><img class="alignnone" title="more" src="http://i623.domety.com/albums/tt312/baolai5/201001/wp_excerpt_002.png" alt="" width="494" height="91" /></p>
<p>那么如果你在主题的首页模板中调用the_content函数，首页的文章摘要就显示more之前的内容。相反，如果没有插入more标签，就会显示全文。</p>
<h3>手动输入摘要</h3>
<p>在首页模板中(比如home.php或index.php)中调用the_excerpt函数显示摘要，如果你在编辑文章的时候，在下面的“摘要”内输入了内容，则会显示该“摘要”里的内容</p>
<p><img class="alignnone" title="输入摘要" src="http://i623.domety.com/albums/tt312/baolai5/201001/wp_excerpt_003.png" alt="" width="509" height="139" /></p>
<p>如果“摘要”里没有内容，就输出more标签前的内容，再如果没有more标签，就输出固定字数的摘要（这个固定的字数好像是默认的，很长，我还没找到更改这个字数的方法，有知道的希望告之）。</p>
<h3>显示固定的字数</h3>
<p>如果你的主机开通了php的mb_string扩展的话，可以使用mb_strimwidth函数来截取文章内容，以达到显示固定字数摘要的目的，比如首页摘要显示前200个字</p>
<pre name="code" class="php">echo mb_strimwidth(strip_tags($post-&gt;post_content),0,200,'......');</pre>
<p>这样就会显示文章的前200个字，随后跟着一个省略号。这个mb_strimwidth函数可以很好截取中文字符。我们再稍改造一下，就可以显示“阅读全文”链接的效果</p>
<pre name="code" class="php">echo mb_strimwidth(strip_tags($post-&gt;post_content),0,200,'&lt;a href="'.get_permalink().'"&gt;......[阅读全文]&lt;/a&gt;');</pre>
<p>但是，如果假如万一你的主机没有激活php的mb_string扩展，使用这个函数就会报错。在这种情况下，我们可以自定义一个类似的函数，下面是我写的一个截取utf-8字符串的函数dm_strimwidth，也是我正在使用的方法</p>
<pre name="code" class="php">function dm_strimwidth($str ,$start , $width ,$trimmarker ){
 $output = preg_replace('/^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$start.'}((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$width.'}).*/s','\1',$str);
 return $output.$trimmarker;
}</pre>
<p>使用方法和前面的mb_strimwidth是一样的，不过使用前你需要把上面的函数定义复制到functions.php文件中，然后调用</p>
<pre name="code" class="php">echo dm_strimwidth(strip_tags($post-&gt;post_content),0,200,'&lt;a href="'.get_permalink().'"&gt;......[阅读全文]&lt;/a&gt;');</pre>
<h3>综合方法</h3>
<p>有时候下面这种做法也是不错的，即如果给文章手动添加了摘要，就显示这个手动添加的摘要，如果没有就显示固定的字数。方法如下：</p>
<pre name="code" class="php">if(has_excerpt()) the_excerpt();
 else
         echo mb_strimwidth(strip_tags($post-&gt;post_content),0,200,'&lt;a href="'.get_permalink().'"&gt;......[阅读全文]&lt;/a&gt;');</pre>
]]></content:encoded>
			<wfw:commentRss>http://domety.com/archives/216/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>

