<?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>FVF.me&#039;Ye &#187; 翻译</title>
	<atom:link href="http://fvf.me/category/translate/feed" rel="self" type="application/rss+xml" />
	<link>http://fvf.me</link>
	<description>我是孤独的根号5</description>
	<lastBuildDate>Mon, 19 Sep 2011 12:10:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Comment.php模板的制作详解</title>
		<link>http://fvf.me/translate/detailed-comment-php-production-template.html</link>
		<comments>http://fvf.me/translate/detailed-comment-php-production-template.html#comments</comments>
		<pubDate>Fri, 07 Aug 2009 02:58:09 +0000</pubDate>
		<dc:creator>死兔子</dc:creator>
				<category><![CDATA[翻译]]></category>
		<category><![CDATA[comment]]></category>
		<category><![CDATA[主题]]></category>

		<guid isPermaLink="false">http://fvf.me/diary/detailed-comment-php-production-template-2.html</guid>
		<description><![CDATA[其实对于改编主题的朋友来说其他的页面都很简单，唯一麻烦的就是评论页也就是Comments.php。因为这个页面对初学者来说太多php代码了。如果不搞懂会出现很多错误！ Nettuts+ 的作者 Gilles Maes 发表的一篇Unraveling the Secrets of WordPress' Comments.php File 详细的向你阐述wordpress主题文件中的comments.php文件。 下面就是我对上面的翻译，如果你的英文很好那么就直接点击上面去查看原文，如果英文不行的话，那么就看看我的译文吧，如有什么看不懂，请给我留言或点击查看英文原文。 如果只是为了参考本文，我制作了如下一个列表，文件你快速的跳到想参阅的部分： 页面的原生PHP代码 代码分析 防止直接访问comments.php文件 是否通过密码验证？ 显示评论 评论模板基本标签 最终结果 评论表单 条件语句预览 插入表单 一些小技巧 Gravatars 评论数 评论链接 编辑评论 评论的交互颜色 显示标签 评论的RSS链接 总结 1. 评论页面的原生PHP代码 &#60;?php if(!empty($_SERVER[&#39;SCRIPT_FILENAME&#39;]) &#38;&#38; &#39;comments.php&#39; == basename($_SERVER[&#39;SCRIPT_FILENAME&#39;])) : ?&#62;&#160; &#60;?php endif; ?&#62;&#160; &#160;&#160;&#160;&#160;&#160; &#60;?php if(!empty($post-&#62;post_password)) : ?&#62;&#160; &#160;&#160;&#160; &#60;?php if($_COOKIE[&#39;wp-postpass_&#39; [...]]]></description>
			<content:encoded><![CDATA[<p>其实对于改编主题的朋友来说其他的页面都很简单，唯一麻烦的就是评论页也就是Comments.php。因为这个页面对初学者来说太多php代码了。如果不搞懂会出现很多错误！  Nettuts+ 的作者 Gilles Maes 发表的一篇Unraveling the Secrets of WordPress' Comments.php File 详细的向你阐述wordpress主题文件中的comments.php文件。  下面就是我对上面的翻译，如果你的英文很好那么就直接点击上面去查看原文，如果英文不行的话，那么就看看我的译文吧，如有什么看不懂，请给我留言或点击查看英文原文。  <span id="more-63"></span>  如果只是为了参考本文，我制作了如下一个列表，文件你快速的跳到想参阅的部分：
<ol>
<li><a href="#php-backend">页面的原生PHP代码</a></li>
<li><a href="#general-code">代码分析</a>
<ol>
<li><a href="#prevent-direct-access">防止直接访问comments.php文件</a></li>
<li><a href="#password-required">是否通过密码验证？</a></li>
</ol>
</li>
<li><a href="#display-comments">显示评论</a>
<ol>
<li><a href="#comment-template-tags">评论模板基本标签</a></li>
<li><a href="#final-result">最终结果</a></li>
</ol>
</li>
<li><a href="#comment-form">评论表单</a>
<ol>
<li><a href="#conditional-statement-overview">条件语句预览</a></li>
<li><a href="#insert-form">插入表单</a></li>
</ol>
</li>
<li><a href="#little-tricks">一些小技巧 </a>
<ol>
<li><a href="#gravatars">Gravatars</a></li>
<li><a href="#comment-numbers">评论数</a></li>
<li><a href="#comment-links">评论链接</a></li>
<li><a href="#editing-comments">编辑评论</a></li>
<li><a href="#alternate-rows">评论的交互颜色</a></li>
<li><a href="#allowed-tags">显示标签</a></li>
<li><a href="#comment-rss">评论的RSS链接</a></li>
</ol>
</li>
<li><a href="#conclusion">总结</a></li>
</ol>
<h4 id="php-backend">1. 评论页面的原生PHP代码</h4>
<div class="source" style="font-family: 'Courier New', 'Lucida Console', Verdana; color: rgb(192, 192, 192); background-color: rgb(0, 0, 0); "> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span>(<span style="color: rgb(192, 192, 192); ">!</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">empty</span>(<span style="color: rgb(204, 204, 0); ">$_SERVER</span><span style="color: rgb(192, 192, 192); ">[</span><span style="color: rgb(187, 187, 0); ">&#39;SCRIPT_FILENAME&#39;</span><span style="color: rgb(192, 192, 192); ">])</span> <span style="color: rgb(192, 192, 192); ">&amp;&amp;</span> <span style="color: rgb(187, 187, 0); ">&#39;comments.php&#39;</span> <span style="color: rgb(192, 192, 192); ">==</span> <span style="color: rgb(192, 192, 192); ">basename</span>(<span style="color: rgb(204, 204, 0); ">$_SERVER</span><span style="color: rgb(192, 192, 192); ">[</span><span style="color: rgb(187, 187, 0); ">&#39;SCRIPT_FILENAME&#39;</span><span style="color: rgb(192, 192, 192); ">]))</span> <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">endif</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span>(<span style="color: rgb(192, 192, 192); ">!</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">empty</span>(<span style="color: rgb(204, 204, 0); ">$post</span><span style="color: rgb(192, 192, 192); ">-&gt;</span><span style="color: rgb(255, 255, 0); ">post_password</span>)) <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span>(<span style="color: rgb(204, 204, 0); ">$_COOKIE</span><span style="color: rgb(192, 192, 192); ">[</span><span style="color: rgb(187, 187, 0); ">&#39;wp-postpass_&#39;</span> <span style="color: rgb(192, 192, 192); ">.</span> <span style="color: rgb(192, 192, 192); ">COOKIEHASH</span><span style="color: rgb(192, 192, 192); ">]</span> <span style="color: rgb(192, 192, 192); ">!=</span> <span style="color: rgb(204, 204, 0); ">$post</span><span style="color: rgb(192, 192, 192); ">-&gt;</span><span style="color: rgb(255, 255, 0); ">post_password</span>) <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">endif</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">endif</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp; <br /> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span>(<span style="color: rgb(204, 204, 0); ">$comments</span>) <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">foreach</span>(<span style="color: rgb(204, 204, 0); ">$comments</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">as</span> <span style="color: rgb(204, 204, 0); ">$comment</span>) <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span> (<span style="color: rgb(204, 204, 0); ">$comment</span><span style="color: rgb(192, 192, 192); ">-&gt;</span><span style="color: rgb(255, 255, 0); ">comment_approved</span> <span style="color: rgb(192, 192, 192); ">==</span> <span style="color: rgb(187, 187, 0); ">&#39;0&#39;</span>) <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">endif</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(192, 192, 192); ">&lt;</span><span style="color: rgb(192, 192, 192); "> ?php endforeach; ?&gt;&nbsp; </span><br /> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">else</span> <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">endif</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp; <br /> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span>(<span style="color: rgb(192, 192, 192); ">comments_open</span>()) <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span>(<span style="color: rgb(192, 192, 192); ">get_option</span>(<span style="color: rgb(187, 187, 0); ">&#39;comment_registration&#39;</span>) <span style="color: rgb(192, 192, 192); ">&amp;&amp;</span> <span style="color: rgb(192, 192, 192); ">!</span><span style="color: rgb(204, 204, 0); ">$user_ID</span>) <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">else</span> <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span>(<span style="color: rgb(204, 204, 0); ">$user_ID</span>) <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">else</span> <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">endif</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">endif</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">else</span> <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">endif</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span></div>
<p>上面那段是是comments.php的最基础的PHP代码，对于新手来说，这些看起来有些吓人，但是请不要担心，看完本教程以后，你的思路会变得很清晰。</p>
<h4 id="php-backend">2. 代码分析</h4>
<h5 id="prevent-direct-access">1. 防止直接访问comments.php文件</h5>
<div class="source" style="font-family: 'Courier New', 'Lucida Console', Verdana; color: rgb(192, 192, 192); background-color: rgb(0, 0, 0); "> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span>(<span style="color: rgb(192, 192, 192); ">!</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">empty</span>(<span style="color: rgb(204, 204, 0); ">$_SERVER</span><span style="color: rgb(192, 192, 192); ">[</span><span style="color: rgb(187, 187, 0); ">&#39;SCRIPT_FILENAME&#39;</span><span style="color: rgb(192, 192, 192); ">])</span> <span style="color: rgb(192, 192, 192); ">&amp;&amp;</span> <span style="color: rgb(187, 187, 0); ">&#39;comments.php&#39;</span> <span style="color: rgb(192, 192, 192); ">==</span> <span style="color: rgb(192, 192, 192); ">basename</span>(<span style="color: rgb(204, 204, 0); ">$_SERVER</span><span style="color: rgb(192, 192, 192); ">[</span><span style="color: rgb(187, 187, 0); ">&#39;SCRIPT_FILENAME&#39;</span><span style="color: rgb(192, 192, 192); ">]))</span> <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">endif</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span></div>
<p>  以上代码是用来防止用户意外直接访问comments.php文件。通常评论页面是被包含在日志页面之中，而不是单独存在的，因此这段代码也可以理解成是一个安全措施。在这些语句中，你可以添加任何你想向直接访问者提示的声明，通常是die陈述，为了帮助理解，我展示如下代码：</p>
<div class="source" style="font-family: 'Courier New', 'Lucida Console', Verdana; color: rgb(192, 192, 192); background-color: rgb(0, 0, 0); "> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span>(<span style="color: rgb(192, 192, 192); ">!</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">empty</span>(<span style="color: rgb(204, 204, 0); ">$_SERVER</span><span style="color: rgb(192, 192, 192); ">[</span><span style="color: rgb(187, 187, 0); ">&#39;SCRIPT_FILENAME&#39;</span><span style="color: rgb(192, 192, 192); ">])</span> <span style="color: rgb(192, 192, 192); ">&amp;&amp;</span> <span style="color: rgb(187, 187, 0); ">&#39;comments.php&#39;</span> <span style="color: rgb(192, 192, 192); ">==</span> <span style="color: rgb(192, 192, 192); ">basename</span>(<span style="color: rgb(204, 204, 0); ">$_SERVER</span><span style="color: rgb(192, 192, 192); ">[</span><span style="color: rgb(187, 187, 0); ">&#39;SCRIPT_FILENAME&#39;</span><span style="color: rgb(192, 192, 192); ">]))</span> <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">die</span>(<span style="color: rgb(187, 187, 0); ">&#39;You can not access this page directly!&#39;</span>); <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">endif</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span></div>
<h5 id="password-required">2. 是否通过密码验证？</h5>
<div class="source" style="font-family: 'Courier New', 'Lucida Console', Verdana; color: rgb(192, 192, 192); background-color: rgb(0, 0, 0); "> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span>(<span style="color: rgb(192, 192, 192); ">!</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">empty</span>(<span style="color: rgb(204, 204, 0); ">$post</span><span style="color: rgb(192, 192, 192); ">-&gt;</span><span style="color: rgb(255, 255, 0); ">post_password</span>)) <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span>(<span style="color: rgb(204, 204, 0); ">$_COOKIE</span><span style="color: rgb(192, 192, 192); ">[</span><span style="color: rgb(187, 187, 0); ">&#39;wp-postpass_&#39;</span> <span style="color: rgb(192, 192, 192); ">.</span> <span style="color: rgb(192, 192, 192); ">COOKIEHASH</span><span style="color: rgb(192, 192, 192); ">]</span> <span style="color: rgb(192, 192, 192); ">!=</span> <span style="color: rgb(204, 204, 0); ">$post</span><span style="color: rgb(192, 192, 192); ">-&gt;</span><span style="color: rgb(255, 255, 0); ">post_password</span>) <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">endif</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">endif</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span></div>
<p>  这一段代码（这看上去是2段，实际上如果把它看作一段那更有意义）是用来检验用户是否通过密码验证，具备足够的权限来阅读日志和评论，显然，如果你没有阅读日志的权限，那么自然没有查看和参与评论的权限。</p>
<p>上述代码的第一个if是用来检测是否存在密码设置。第二个if是用来检测是否存在一个包含密码的cookie文件，如果不存在就显示错误信息。你可以在第二个if句块的任意位置自定义这些错误信息。</p>
<h4 id="display-comments">3. 显示评论</h4>
<div class="source" style="font-family: 'Courier New', 'Lucida Console', Verdana; color: rgb(192, 192, 192); background-color: rgb(0, 0, 0); "> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span>(<span style="color: rgb(204, 204, 0); ">$comments</span>)<span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">foreach</span> (<span style="color: rgb(204, 204, 0); ">$comments</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">as</span> <span style="color: rgb(204, 204, 0); ">$comment</span>) <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span> (<span style="color: rgb(204, 204, 0); ">$comment</span><span style="color: rgb(192, 192, 192); ">-&gt;</span><span style="color: rgb(255, 255, 0); ">comment_approved</span> <span style="color: rgb(192, 192, 192); ">==</span> <span style="color: rgb(187, 187, 0); ">&#39;0&#39;</span>) <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">endif</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">endforeach</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">else</span> <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">endif</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span></div>
<p>  第一个条件语句(if($comments))是用来检测是否存在评论，如果存在的话，就按照foreach语句指定的方式循环显示每一条评论，直至结束。在foreach语句块中，你会发现有这么一个条件语句：if($comment-&gt;comment_approved ==‘0′)这是用来检测评论是否通过了审核，假如没通过审核就会提示错误信息。</p>
<p>举例如下：</p>
<div class="source" style="font-family: 'Courier New', 'Lucida Console', Verdana; color: rgb(192, 192, 192); background-color: rgb(0, 0, 0); "> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span>(<span style="color: rgb(204, 204, 0); ">$comments</span>) <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;ol&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">foreach</span>(<span style="color: rgb(204, 204, 0); ">$comments</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">as</span> <span style="color: rgb(204, 204, 0); ">$comment</span>) <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;li&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span>(<span style="color: rgb(204, 204, 0); ">$comment</span><span style="color: rgb(192, 192, 192); ">-&gt;</span><span style="color: rgb(255, 255, 0); ">comment_approved</span> <span style="color: rgb(192, 192, 192); ">==</span> <span style="color: rgb(187, 187, 0); ">&#39;0&#39;</span>) <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;p&gt;</span><span style="color: rgb(192, 192, 192); ">Your comment is awaiting approval</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/p&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">endif</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;p&gt;</span><span style="color: rgb(192, 192, 192); ">Your comment</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/p&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/li&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">endforeach</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/ol&gt;</span>&nbsp; <br /> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">else</span> <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;p&gt;</span><span style="color: rgb(192, 192, 192); ">No comments</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/p&gt;</span>&nbsp; <br /> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">endif</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span></div>
<h5 id="comment-template-tags">1. 评论模板基本标签</h5>
<p>您需要使用Wordpress提供的预定义标签，来给评论页面添加一些功能。</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="231" valign="top">模板标签</td>
<td width="327" valign="top">描述</td>
</tr>
<tr>
<td width="231" valign="top">&lt;?php comment_ID(); ?&gt;</td>
<td width="327" valign="top">评论的ID</td>
</tr>
<tr>
<td width="231" valign="top">&lt;?php comment_author(); ?&gt;</td>
<td width="327" valign="top">评论的作者</td>
</tr>
<tr>
<td width="231" valign="top">&lt;?php comment_author_link(); ?&gt;</td>
<td width="327" valign="top">评论者的链接</td>
</tr>
<tr>
<td width="231" valign="top">&lt;?php comment_type(); ?&gt;</td>
<td width="327" valign="top">评论的类别，pingback,trackback或者是一个单纯的评论</td>
</tr>
<tr>
<td width="231" valign="top">&lt;?php comment_text(); ?&gt;</td>
<td width="327" valign="top">评论内容</td>
</tr>
<tr>
<td width="231" valign="top">&lt;?php comment_date(); ?&gt;</td>
<td width="327" valign="top">评论的日期</td>
</tr>
<tr>
<td width="231" valign="top">&lt;?php comment_time(); ?&gt;</td>
<td width="327" valign="top">评论的时间</td>
</tr>
</tbody>
</table>
<h5 id="#final-result">2. 最终结果</h5>
<div class="source" style="font-family: 'Courier New', 'Lucida Console', Verdana; color: rgb(192, 192, 192); background-color: rgb(0, 0, 0); "> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span>(<span style="color: rgb(204, 204, 0); ">$comments</span>) <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;ol&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">foreach</span>(<span style="color: rgb(204, 204, 0); ">$comments</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">as</span> <span style="color: rgb(204, 204, 0); ">$comment</span>) <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;li</span> <span style="color: rgb(255, 255, 0); ">id=</span><span style="color: rgb(187, 187, 0); ">&quot;comment-</span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(192, 192, 192); ">comment_ID</span>(); <span style="color: rgb(255, 255, 255); ">?&gt;</span><span style="color: rgb(187, 187, 0); ">&quot;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span> (<span style="color: rgb(204, 204, 0); ">$comment</span><span style="color: rgb(192, 192, 192); ">-&gt;</span><span style="color: rgb(255, 255, 0); ">comment_approved</span> <span style="color: rgb(192, 192, 192); ">==</span> <span style="color: rgb(187, 187, 0); ">&#39;0&#39;</span>) <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;p&gt;</span><span style="color: rgb(192, 192, 192); ">Your comment is awaiting approval</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/p&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">endif</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(192, 192, 192); ">comment_text</span>(); <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;cite&gt;</span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(192, 192, 192); ">comment_type</span>(); <span style="color: rgb(255, 255, 255); ">?&gt;</span><span style="color: rgb(192, 192, 192); "> by </span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(192, 192, 192); ">comment_author_link</span>(); <span style="color: rgb(255, 255, 255); ">?&gt;</span><span style="color: rgb(192, 192, 192); "> on </span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(192, 192, 192); ">comment_date</span>(); <span style="color: rgb(255, 255, 255); ">?&gt;</span><span style="color: rgb(192, 192, 192); "> at </span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(192, 192, 192); ">comment_time</span>(); <span style="color: rgb(255, 255, 255); ">?&gt;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/cite&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/li&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">endforeach</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/ol&gt;</span>&nbsp; <br /> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">else</span> <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;p&gt;</span><span style="color: rgb(192, 192, 192); ">No comments yet</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/p&gt;</span>&nbsp; <br /> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">endif</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span></div>
<p>  把这段代码插入到你的 comments.php 文件中，这样你就有一个评论的有序列表，并且显示你定义的内容。</p>
<h4 id="comment-form">4. 评论表单</h4>
<p>现在我们开始进入到评论表单部分的处理，评论表单皮肤的定制算是 comments.php文件中的一个难点。</p>
<p>你也许会被众多的语句吓到了，比如“你已经登陆，请……”，这些往往给新手造成了困扰：错误的标签放置可能造成整个评论表单失效，而这往往并不是PHP语法上的错误。</p>
<p>为了让你尽快的对评论表单有一个全面的认识，我接下来要详细讲解这些语句块，并且对HTML代码也做了相应介绍，让你明白为什么它们会出现在这个位置。</p>
<h5 id="conditional-statement-overview">1. 条件语句预览</h5>
<div class="source" style="font-family: 'Courier New', 'Lucida Console', Verdana; color: rgb(192, 192, 192); background-color: rgb(0, 0, 0); "> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span>(<span style="color: rgb(192, 192, 192); ">comments_open</span>()) <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span>(<span style="color: rgb(192, 192, 192); ">get_option</span>(<span style="color: rgb(187, 187, 0); ">&#39;comment_registration&#39;</span>) <span style="color: rgb(192, 192, 192); ">&amp;&amp;</span> <span style="color: rgb(192, 192, 192); ">!</span><span style="color: rgb(204, 204, 0); ">$user_ID</span>) <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">else</span> <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span>(<span style="color: rgb(204, 204, 0); ">$user_ID</span>) <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">else</span> <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">endif</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">endif</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">else</span> <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">endif</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span></div>
<p>  我们碰到的第一个条件语句是 。这个函数主要目的是为了检测日志是否允许评论。很显然，如果该日志是不允许评论状态，那么你就不能发表评论，也就是说完全没有必要显示评论表单。当关闭评论后，你可以放置一些提示信息于上述代码最后两个标签 和 之间，以便让访问者知道。</p>
<p>第二个条件语句是 () 。这个函数是用来检测你是否要注册后才能评论以及目前是否登陆了帐号。如果上面的两个条件都不满足，那么访问者就会被引导到登陆页面。假如博客的主人设置为不用注册即可发表评论，或者是你已经登陆，那么就将接着执行 else 部分并显示出评论表单。</p>
<p>最后一个条件语句是用来检测你否已经登出帐号。此检查的目的很简单，假如你已经登陆了，那么评论表单就不会显示姓名、Email、主页地址等填写项，因为对于已登陆的用户来说这是没有实在意义的。</p>
<h5 id="insert-form">2. 插入表单</h5>
<p>我们已经分析完 coments.php 文件中的所有条件语句，接下来可以插入评论表单。</p>
<p>我猜你肯定首先想到的是：在哪开始插入表单？不要紧张，不妨凭感觉走 第二个条件语句是用来检测你是否已经登陆，因此你至少要在这个判断条件之后才能插入表单，这样我们也就确定了评论表单的位置。</p>
<div class="source" style="font-family: 'Courier New', 'Lucida Console', Verdana; color: rgb(192, 192, 192); background-color: rgb(0, 0, 0); "> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span>(<span style="color: rgb(192, 192, 192); ">comments_open</span>()) <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span>(<span style="color: rgb(192, 192, 192); ">get_option</span>(<span style="color: rgb(187, 187, 0); ">&#39;comment_registration&#39;</span>) <span style="color: rgb(192, 192, 192); ">&amp;&amp;</span> <span style="color: rgb(192, 192, 192); ">!</span><span style="color: rgb(204, 204, 0); ">$user_ID</span>) <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;p&gt;</span><span style="color: rgb(192, 192, 192); ">You must be </span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;a</span> <span style="color: rgb(255, 255, 0); ">href=</span><span style="color: rgb(187, 187, 0); ">&quot;&amp;lt;?php echo get_option(&#39;siteurl&#39;); ?&amp;gt;/wp-login.php?redirect_to=&amp;lt; ?php echo urlencode(get_permalink()); ?&amp;gt;&quot;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&gt;</span><span style="color: rgb(192, 192, 192); ">logged in</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/a&gt;</span><span style="color: rgb(192, 192, 192); "> to post a comment.</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/p&gt;</span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">else</span> <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;form</span> <span style="color: rgb(255, 255, 0); ">action=</span><span style="color: rgb(187, 187, 0); ">&quot;&amp;lt;?php echo get_option(&#39;siteurl&#39;); ?&amp;gt;/wp-comments-post.php&quot;</span> <span style="color: rgb(255, 255, 0); ">method=</span><span style="color: rgb(187, 187, 0); ">&quot;post&quot;</span> <span style="color: rgb(255, 255, 0); ">id=</span><span style="color: rgb(187, 187, 0); ">&quot;commentform&quot;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span>(<span style="color: rgb(204, 204, 0); ">$user_ID</span>) <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">else</span> <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">endif</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/form&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">endif</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">else</span> <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;p&gt;</span><span style="color: rgb(192, 192, 192); ">The comments are closed.</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/p&gt;</span>&nbsp; <br /> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">endif</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span></div>
<p>  我还插入了登陆页面的链接，这只是我在默认的 comments.php 文件中发现的。就像我之前说的那样，最后一个条件句是用来判断你是否登陆。因此，姓名、Email、主页地址只在你没有登陆时才有必要显示。因此我们可以在那个位置插入这些东西。</p>
<div class="source" style="font-family: 'Courier New', 'Lucida Console', Verdana; color: rgb(192, 192, 192); background-color: rgb(0, 0, 0); "> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span>(<span style="color: rgb(192, 192, 192); ">comments_open</span>()) <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span>(<span style="color: rgb(192, 192, 192); ">get_option</span>(<span style="color: rgb(187, 187, 0); ">&#39;comment_registration&#39;</span>) <span style="color: rgb(192, 192, 192); ">&amp;&amp;</span> <span style="color: rgb(192, 192, 192); ">!</span><span style="color: rgb(204, 204, 0); ">$user_ID</span>) <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;p&gt;</span><span style="color: rgb(192, 192, 192); ">You must be </span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;a</span> <span style="color: rgb(255, 255, 0); ">href=</span><span style="color: rgb(187, 187, 0); ">&quot;</span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">echo</span> <span style="color: rgb(192, 192, 192); ">get_option</span>(<span style="color: rgb(187, 187, 0); ">&#39;siteurl&#39;</span>); <span style="color: rgb(255, 255, 255); ">?&gt;</span><span style="color: rgb(187, 187, 0); ">/wp-login.php?redirect_to=</span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">echo</span> <span style="color: rgb(192, 192, 192); ">urlencode</span>(<span style="color: rgb(192, 192, 192); ">get_permalink</span>()); <span style="color: rgb(255, 255, 255); ">?&gt;</span><span style="color: rgb(187, 187, 0); ">&quot;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&gt;</span><span style="color: rgb(192, 192, 192); ">logged in</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/a&gt;</span><span style="color: rgb(192, 192, 192); "> to post a comment.</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/p&gt;</span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">else</span> <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;form</span> <span style="color: rgb(255, 255, 0); ">action=</span><span style="color: rgb(187, 187, 0); ">&quot;</span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">echo</span> <span style="color: rgb(192, 192, 192); ">get_option</span>(<span style="color: rgb(187, 187, 0); ">&#39;siteurl&#39;</span>); <span style="color: rgb(255, 255, 255); ">?&gt;</span><span style="color: rgb(187, 187, 0); ">/wp-comments-post.php&quot;</span> <span style="color: rgb(255, 255, 0); ">method=</span><span style="color: rgb(187, 187, 0); ">&quot;post&quot;</span> <span style="color: rgb(255, 255, 0); ">id=</span><span style="color: rgb(187, 187, 0); ">&quot;commentform&quot;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span>(<span style="color: rgb(204, 204, 0); ">$user_ID</span>) <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;p&gt;</span><span style="color: rgb(192, 192, 192); ">Logged in as </span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;a</span> <span style="color: rgb(255, 255, 0); ">href=</span><span style="color: rgb(187, 187, 0); ">&quot;</span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">echo</span> <span style="color: rgb(192, 192, 192); ">get_option</span>(<span style="color: rgb(187, 187, 0); ">&#39;siteurl&#39;</span>); <span style="color: rgb(255, 255, 255); ">?&gt;</span><span style="color: rgb(187, 187, 0); ">/wp-admin/profile.php&quot;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&gt;</span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">echo</span> <span style="color: rgb(204, 204, 0); ">$user_identity</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/a&gt;</span><span style="color: rgb(192, 192, 192); ">. </span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;a</span> <span style="color: rgb(255, 255, 0); ">href=</span><span style="color: rgb(187, 187, 0); ">&quot;</span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">echo</span> <span style="color: rgb(192, 192, 192); ">get_option</span>(<span style="color: rgb(187, 187, 0); ">&#39;siteurl&#39;</span>); <span style="color: rgb(255, 255, 255); ">?&gt;</span><span style="color: rgb(187, 187, 0); ">/wp-login.php?action=logout&quot;</span> <span style="color: rgb(255, 255, 0); ">title=</span><span style="color: rgb(187, 187, 0); ">&quot;Log out of this account&quot;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&gt;</span><span style="color: rgb(192, 192, 192); ">Log out </span><span style="color: rgb(255, 255, 255); ">&amp;raquo;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/a&gt;&lt;/p&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">else</span> <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;p&gt;&lt;input</span> <span style="color: rgb(255, 255, 0); ">type=</span><span style="color: rgb(187, 187, 0); ">&quot;text&quot;</span> <span style="color: rgb(255, 255, 0); ">name=</span><span style="color: rgb(187, 187, 0); ">&quot;author&quot;</span> <span style="color: rgb(255, 255, 0); ">id=</span><span style="color: rgb(187, 187, 0); ">&quot;author&quot;</span> <span style="color: rgb(255, 255, 0); ">value=</span><span style="color: rgb(187, 187, 0); ">&quot;</span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">echo</span> <span style="color: rgb(204, 204, 0); ">$comment_author</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span><span style="color: rgb(187, 187, 0); ">&quot;</span> <span style="color: rgb(255, 255, 0); ">size=</span><span style="color: rgb(187, 187, 0); ">&quot;22&quot;</span> <span style="color: rgb(255, 255, 0); ">tabindex=</span><span style="color: rgb(187, 187, 0); ">&quot;1&quot;</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">/&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;label</span> <span style="color: rgb(255, 255, 0); ">for=</span><span style="color: rgb(187, 187, 0); ">&quot;author&quot;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&gt;&lt;small&gt;</span><span style="color: rgb(192, 192, 192); ">Name </span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span>(<span style="color: rgb(204, 204, 0); ">$req</span>) <span style="color: rgb(255, 255, 0); font-weight: bold; ">echo</span> <span style="color: rgb(187, 187, 0); ">&quot;(required)&quot;</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/small&gt;&lt;/label&gt;&lt;/p&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;p&gt;&lt;input</span> <span style="color: rgb(255, 255, 0); ">type=</span><span style="color: rgb(187, 187, 0); ">&quot;text&quot;</span> <span style="color: rgb(255, 255, 0); ">name=</span><span style="color: rgb(187, 187, 0); ">&quot;email&quot;</span> <span style="color: rgb(255, 255, 0); ">id=</span><span style="color: rgb(187, 187, 0); ">&quot;email&quot;</span> <span style="color: rgb(255, 255, 0); ">value=</span><span style="color: rgb(187, 187, 0); ">&quot;</span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">echo</span> <span style="color: rgb(204, 204, 0); ">$comment_author_email</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span><span style="color: rgb(187, 187, 0); ">&quot;</span> <span style="color: rgb(255, 255, 0); ">size=</span><span style="color: rgb(187, 187, 0); ">&quot;22&quot;</span> <span style="color: rgb(255, 255, 0); ">tabindex=</span><span style="color: rgb(187, 187, 0); ">&quot;2&quot;</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">/&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;label</span> <span style="color: rgb(255, 255, 0); ">for=</span><span style="color: rgb(187, 187, 0); ">&quot;email&quot;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&gt;&lt;small&gt;</span><span style="color: rgb(192, 192, 192); ">Mail (will not be published) </span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span>(<span style="color: rgb(204, 204, 0); ">$req</span>) <span style="color: rgb(255, 255, 0); font-weight: bold; ">echo</span> <span style="color: rgb(187, 187, 0); ">&quot;(required)&quot;</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/small&gt;&lt;/label&gt;&lt;/p&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;p&gt;&lt;input</span> <span style="color: rgb(255, 255, 0); ">type=</span><span style="color: rgb(187, 187, 0); ">&quot;text&quot;</span> <span style="color: rgb(255, 255, 0); ">name=</span><span style="color: rgb(187, 187, 0); ">&quot;url&quot;</span> <span style="color: rgb(255, 255, 0); ">id=</span><span style="color: rgb(187, 187, 0); ">&quot;url&quot;</span> <span style="color: rgb(255, 255, 0); ">value=</span><span style="color: rgb(187, 187, 0); ">&quot;</span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">echo</span> <span style="color: rgb(204, 204, 0); ">$comment_author_url</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span><span style="color: rgb(187, 187, 0); ">&quot;</span> <span style="color: rgb(255, 255, 0); ">size=</span><span style="color: rgb(187, 187, 0); ">&quot;22&quot;</span> <span style="color: rgb(255, 255, 0); ">tabindex=</span><span style="color: rgb(187, 187, 0); ">&quot;3&quot;</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">/&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;label</span> <span style="color: rgb(255, 255, 0); ">for=</span><span style="color: rgb(187, 187, 0); ">&quot;url&quot;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&gt;&lt;small&gt;</span><span style="color: rgb(192, 192, 192); ">Website</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/small&gt;&lt;/label&gt;&lt;/p&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">endif</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/form&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">endif</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">else</span> <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;p&gt;</span><span style="color: rgb(192, 192, 192); ">The comments are closed.</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/p&gt;</span>&nbsp; <br /> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">endif</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span></div>
<p>  非常棒！我们只需要插入一些简单的代码，比如文件域和提交按钮，把这些通通播入到最后一个判断语句块的后面，因为这些元素跟你有没有登陆是不相干的。</p>
<div class="source" style="font-family: 'Courier New', 'Lucida Console', Verdana; color: rgb(192, 192, 192); background-color: rgb(0, 0, 0); "> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span>(<span style="color: rgb(192, 192, 192); ">comments_open</span>()) <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span>(<span style="color: rgb(192, 192, 192); ">get_option</span>(<span style="color: rgb(187, 187, 0); ">&#39;comment_registration&#39;</span>) <span style="color: rgb(192, 192, 192); ">&amp;&amp;</span> <span style="color: rgb(192, 192, 192); ">!</span><span style="color: rgb(204, 204, 0); ">$user_ID</span>) <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;p&gt;</span><span style="color: rgb(192, 192, 192); ">You must be </span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;a</span> <span style="color: rgb(255, 255, 0); ">href=</span><span style="color: rgb(187, 187, 0); ">&quot;</span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">echo</span> <span style="color: rgb(192, 192, 192); ">get_option</span>(<span style="color: rgb(187, 187, 0); ">&#39;siteurl&#39;</span>); <span style="color: rgb(255, 255, 255); ">?&gt;</span><span style="color: rgb(187, 187, 0); ">/wp-login.php?redirect_to=</span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">echo</span> <span style="color: rgb(192, 192, 192); ">urlencode</span>(<span style="color: rgb(192, 192, 192); ">get_permalink</span>()); <span style="color: rgb(255, 255, 255); ">?&gt;</span><span style="color: rgb(187, 187, 0); ">&quot;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&gt;</span><span style="color: rgb(192, 192, 192); ">logged in</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/a&gt;</span><span style="color: rgb(192, 192, 192); "> to post a comment.</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/p&gt;</span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">else</span> <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;form</span> <span style="color: rgb(255, 255, 0); ">action=</span><span style="color: rgb(187, 187, 0); ">&quot;</span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">echo</span> <span style="color: rgb(192, 192, 192); ">get_option</span>(<span style="color: rgb(187, 187, 0); ">&#39;siteurl&#39;</span>); <span style="color: rgb(255, 255, 255); ">?&gt;</span><span style="color: rgb(187, 187, 0); ">/wp-comments-post.php&quot;</span> <span style="color: rgb(255, 255, 0); ">method=</span><span style="color: rgb(187, 187, 0); ">&quot;post&quot;</span> <span style="color: rgb(255, 255, 0); ">id=</span><span style="color: rgb(187, 187, 0); ">&quot;commentform&quot;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span>(<span style="color: rgb(204, 204, 0); ">$user_ID</span>) <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;p&gt;</span><span style="color: rgb(192, 192, 192); ">Logged in as </span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;a</span> <span style="color: rgb(255, 255, 0); ">href=</span><span style="color: rgb(187, 187, 0); ">&quot;</span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">echo</span> <span style="color: rgb(192, 192, 192); ">get_option</span>(<span style="color: rgb(187, 187, 0); ">&#39;siteurl&#39;</span>); <span style="color: rgb(255, 255, 255); ">?&gt;</span><span style="color: rgb(187, 187, 0); ">/wp-admin/profile.php&quot;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&gt;</span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">echo</span> <span style="color: rgb(204, 204, 0); ">$user_identity</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/a&gt;</span><span style="color: rgb(192, 192, 192); ">. </span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;a</span> <span style="color: rgb(255, 255, 0); ">href=</span><span style="color: rgb(187, 187, 0); ">&quot;</span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">echo</span> <span style="color: rgb(192, 192, 192); ">get_option</span>(<span style="color: rgb(187, 187, 0); ">&#39;siteurl&#39;</span>); <span style="color: rgb(255, 255, 255); ">?&gt;</span><span style="color: rgb(187, 187, 0); ">/wp-login.php?action=logout&quot;</span> <span style="color: rgb(255, 255, 0); ">title=</span><span style="color: rgb(187, 187, 0); ">&quot;Log out of this account&quot;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&gt;</span><span style="color: rgb(192, 192, 192); ">Log out </span><span style="color: rgb(255, 255, 255); ">&amp;raquo;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/a&gt;&lt;/p&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">else</span> <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;p&gt;&lt;input</span> <span style="color: rgb(255, 255, 0); ">type=</span><span style="color: rgb(187, 187, 0); ">&quot;text&quot;</span> <span style="color: rgb(255, 255, 0); ">name=</span><span style="color: rgb(187, 187, 0); ">&quot;author&quot;</span> <span style="color: rgb(255, 255, 0); ">id=</span><span style="color: rgb(187, 187, 0); ">&quot;author&quot;</span> <span style="color: rgb(255, 255, 0); ">value=</span><span style="color: rgb(187, 187, 0); ">&quot;</span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">echo</span> <span style="color: rgb(204, 204, 0); ">$comment_author</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span><span style="color: rgb(187, 187, 0); ">&quot;</span> <span style="color: rgb(255, 255, 0); ">size=</span><span style="color: rgb(187, 187, 0); ">&quot;22&quot;</span> <span style="color: rgb(255, 255, 0); ">tabindex=</span><span style="color: rgb(187, 187, 0); ">&quot;1&quot;</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">/&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;label</span> <span style="color: rgb(255, 255, 0); ">for=</span><span style="color: rgb(187, 187, 0); ">&quot;author&quot;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&gt;&lt;small&gt;</span><span style="color: rgb(192, 192, 192); ">Name </span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span>(<span style="color: rgb(204, 204, 0); ">$req</span>) <span style="color: rgb(255, 255, 0); font-weight: bold; ">echo</span> <span style="color: rgb(187, 187, 0); ">&quot;(required)&quot;</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/small&gt;&lt;/label&gt;&lt;/p&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;p&gt;&lt;input</span> <span style="color: rgb(255, 255, 0); ">type=</span><span style="color: rgb(187, 187, 0); ">&quot;text&quot;</span> <span style="color: rgb(255, 255, 0); ">name=</span><span style="color: rgb(187, 187, 0); ">&quot;email&quot;</span> <span style="color: rgb(255, 255, 0); ">id=</span><span style="color: rgb(187, 187, 0); ">&quot;email&quot;</span> <span style="color: rgb(255, 255, 0); ">value=</span><span style="color: rgb(187, 187, 0); ">&quot;</span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">echo</span> <span style="color: rgb(204, 204, 0); ">$comment_author_email</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span><span style="color: rgb(187, 187, 0); ">&quot;</span> <span style="color: rgb(255, 255, 0); ">size=</span><span style="color: rgb(187, 187, 0); ">&quot;22&quot;</span> <span style="color: rgb(255, 255, 0); ">tabindex=</span><span style="color: rgb(187, 187, 0); ">&quot;2&quot;</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">/&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;label</span> <span style="color: rgb(255, 255, 0); ">for=</span><span style="color: rgb(187, 187, 0); ">&quot;email&quot;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&gt;&lt;small&gt;</span><span style="color: rgb(192, 192, 192); ">Mail (will not be published) </span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span>(<span style="color: rgb(204, 204, 0); ">$req</span>) <span style="color: rgb(255, 255, 0); font-weight: bold; ">echo</span> <span style="color: rgb(187, 187, 0); ">&quot;(required)&quot;</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/small&gt;&lt;/label&gt;&lt;/p&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;p&gt;&lt;input</span> <span style="color: rgb(255, 255, 0); ">type=</span><span style="color: rgb(187, 187, 0); ">&quot;text&quot;</span> <span style="color: rgb(255, 255, 0); ">name=</span><span style="color: rgb(187, 187, 0); ">&quot;url&quot;</span> <span style="color: rgb(255, 255, 0); ">id=</span><span style="color: rgb(187, 187, 0); ">&quot;url&quot;</span> <span style="color: rgb(255, 255, 0); ">value=</span><span style="color: rgb(187, 187, 0); ">&quot;</span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">echo</span> <span style="color: rgb(204, 204, 0); ">$comment_author_url</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span><span style="color: rgb(187, 187, 0); ">&quot;</span> <span style="color: rgb(255, 255, 0); ">size=</span><span style="color: rgb(187, 187, 0); ">&quot;22&quot;</span> <span style="color: rgb(255, 255, 0); ">tabindex=</span><span style="color: rgb(187, 187, 0); ">&quot;3&quot;</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">/&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;label</span> <span style="color: rgb(255, 255, 0); ">for=</span><span style="color: rgb(187, 187, 0); ">&quot;url&quot;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&gt;&lt;small&gt;</span><span style="color: rgb(192, 192, 192); ">Website</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/small&gt;&lt;/label&gt;&lt;/p&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">endif</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;p&gt;&lt;textarea</span> <span style="color: rgb(255, 255, 0); ">name=</span><span style="color: rgb(187, 187, 0); ">&quot;comment&quot;</span> <span style="color: rgb(255, 255, 0); ">id=</span><span style="color: rgb(187, 187, 0); ">&quot;comment&quot;</span> <span style="color: rgb(255, 255, 0); ">cols=</span><span style="color: rgb(187, 187, 0); ">&quot;100%&quot;</span> <span style="color: rgb(255, 255, 0); ">rows=</span><span style="color: rgb(187, 187, 0); ">&quot;10&quot;</span> <span style="color: rgb(255, 255, 0); ">tabindex=</span><span style="color: rgb(187, 187, 0); ">&quot;4&quot;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&gt;&lt;/textarea&gt;&lt;/p&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;p&gt;&lt;input</span> <span style="color: rgb(255, 255, 0); ">name=</span><span style="color: rgb(187, 187, 0); ">&quot;submit&quot;</span> <span style="color: rgb(255, 255, 0); ">type=</span><span style="color: rgb(187, 187, 0); ">&quot;submit&quot;</span> <span style="color: rgb(255, 255, 0); ">id=</span><span style="color: rgb(187, 187, 0); ">&quot;submit&quot;</span> <span style="color: rgb(255, 255, 0); ">tabindex=</span><span style="color: rgb(187, 187, 0); ">&quot;5&quot;</span> <span style="color: rgb(255, 255, 0); ">value=</span><span style="color: rgb(187, 187, 0); ">&quot;Submit Comment&quot;</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">/&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;input</span> <span style="color: rgb(255, 255, 0); ">type=</span><span style="color: rgb(187, 187, 0); ">&quot;hidden&quot;</span> <span style="color: rgb(255, 255, 0); ">name=</span><span style="color: rgb(187, 187, 0); ">&quot;comment_post_ID&quot;</span> <span style="color: rgb(255, 255, 0); ">value=</span><span style="color: rgb(187, 187, 0); ">&quot;</span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">echo</span> <span style="color: rgb(204, 204, 0); ">$id</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span><span style="color: rgb(187, 187, 0); ">&quot;</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">/&gt;&lt;/p&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(192, 192, 192); ">do_action</span>(<span style="color: rgb(187, 187, 0); ">&#39;comment_form&#39;</span><span style="color: rgb(192, 192, 192); ">,</span> <span style="color: rgb(204, 204, 0); ">$post</span><span style="color: rgb(192, 192, 192); ">-&gt;</span><span style="color: rgb(255, 255, 0); ">ID</span>); <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/form&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">endif</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">else</span> <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;p&gt;</span><span style="color: rgb(192, 192, 192); ">The comments are closed.</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/p&gt;</span>&nbsp; <br /> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">endif</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span></div>
<p>  这些代码简洁明了，不言自明：一个文本域、一个提交按钮，还有一个由评论的 future ID 控制的隐藏的输入区域，最后是一个PHP小代码段</p>
<div class="source" style="font-family: 'Courier New', 'Lucida Console', Verdana; color: rgb(192, 192, 192); background-color: rgb(0, 0, 0); "> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span>(<span style="color: rgb(192, 192, 192); ">comments_open</span>()) <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span>(<span style="color: rgb(192, 192, 192); ">get_option</span>(<span style="color: rgb(187, 187, 0); ">&#39;comment_registration&#39;</span>) <span style="color: rgb(192, 192, 192); ">&amp;&amp;</span> <span style="color: rgb(192, 192, 192); ">!</span><span style="color: rgb(204, 204, 0); ">$user_ID</span>) <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;p&gt;</span><span style="color: rgb(192, 192, 192); ">You must be </span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;a</span> <span style="color: rgb(255, 255, 0); ">href=</span><span style="color: rgb(187, 187, 0); ">&quot;&amp;lt;?php echo get_option(&#39;siteurl&#39;); ?&amp;gt;/wp-login.php?redirect_to=&amp;lt; ?php echo urlencode(get_permalink()); ?&amp;gt;&quot;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&gt;</span><span style="color: rgb(192, 192, 192); ">logged in</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/a&gt;</span><span style="color: rgb(192, 192, 192); "> to post a comment.</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/p&gt;</span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">else</span> <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;form</span> <span style="color: rgb(255, 255, 0); ">action=</span><span style="color: rgb(187, 187, 0); ">&quot;&amp;lt;?php echo get_option(&#39;siteurl&#39;); ?&amp;gt;/wp-comments-post.php&quot;</span> <span style="color: rgb(255, 255, 0); ">method=</span><span style="color: rgb(187, 187, 0); ">&quot;post&quot;</span> <span style="color: rgb(255, 255, 0); ">id=</span><span style="color: rgb(187, 187, 0); ">&quot;commentform&quot;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span>(<span style="color: rgb(204, 204, 0); ">$user_ID</span>) <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;p&gt;</span><span style="color: rgb(192, 192, 192); ">Logged in as </span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;a</span> <span style="color: rgb(255, 255, 0); ">href=</span><span style="color: rgb(187, 187, 0); ">&quot;&amp;lt;?php echo get_option(&#39;siteurl&#39;); ?&amp;gt;/wp-admin/profile.php&quot;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&gt;</span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">echo</span> <span style="color: rgb(204, 204, 0); ">$user_identity</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/a&gt;</span><span style="color: rgb(192, 192, 192); ">. </span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;a</span> <span style="color: rgb(255, 255, 0); ">href=</span><span style="color: rgb(187, 187, 0); ">&quot;&amp;lt;?php echo get_option(&#39;siteurl&#39;); ?&amp;gt;/wp-login.php?action=logout&quot;</span> <span style="color: rgb(255, 255, 0); ">title=</span><span style="color: rgb(187, 187, 0); ">&quot;Log out of this account&quot;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&gt;</span><span style="color: rgb(192, 192, 192); ">Log out </span><span style="color: rgb(255, 255, 255); ">&amp;raquo;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/a&gt;&lt;/p&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">else</span> <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;p&gt;&lt;input</span> <span style="color: rgb(255, 255, 0); ">type=</span><span style="color: rgb(187, 187, 0); ">&quot;text&quot;</span> <span style="color: rgb(255, 255, 0); ">name=</span><span style="color: rgb(187, 187, 0); ">&quot;author&quot;</span> <span style="color: rgb(255, 255, 0); ">id=</span><span style="color: rgb(187, 187, 0); ">&quot;author&quot;</span> <span style="color: rgb(255, 255, 0); ">value=</span><span style="color: rgb(187, 187, 0); ">&quot;</span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">echo</span> <span style="color: rgb(204, 204, 0); ">$comment_author</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span><span style="color: rgb(187, 187, 0); ">&quot;</span> <span style="color: rgb(255, 255, 0); ">size=</span><span style="color: rgb(187, 187, 0); ">&quot;22&quot;</span> <span style="color: rgb(255, 255, 0); ">tabindex=</span><span style="color: rgb(187, 187, 0); ">&quot;1&quot;</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">/&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;label</span> <span style="color: rgb(255, 255, 0); ">for=</span><span style="color: rgb(187, 187, 0); ">&quot;author&quot;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&gt;&lt;small&gt;</span><span style="color: rgb(192, 192, 192); ">Name </span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span>(<span style="color: rgb(204, 204, 0); ">$req</span>) <span style="color: rgb(255, 255, 0); font-weight: bold; ">echo</span> <span style="color: rgb(187, 187, 0); ">&quot;(required)&quot;</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/small&gt;&lt;/label&gt;&lt;/p&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;p&gt;&lt;input</span> <span style="color: rgb(255, 255, 0); ">type=</span><span style="color: rgb(187, 187, 0); ">&quot;text&quot;</span> <span style="color: rgb(255, 255, 0); ">name=</span><span style="color: rgb(187, 187, 0); ">&quot;email&quot;</span> <span style="color: rgb(255, 255, 0); ">id=</span><span style="color: rgb(187, 187, 0); ">&quot;email&quot;</span> <span style="color: rgb(255, 255, 0); ">value=</span><span style="color: rgb(187, 187, 0); ">&quot;</span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">echo</span> <span style="color: rgb(204, 204, 0); ">$comment_author_email</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span><span style="color: rgb(187, 187, 0); ">&quot;</span> <span style="color: rgb(255, 255, 0); ">size=</span><span style="color: rgb(187, 187, 0); ">&quot;22&quot;</span> <span style="color: rgb(255, 255, 0); ">tabindex=</span><span style="color: rgb(187, 187, 0); ">&quot;2&quot;</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">/&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;label</span> <span style="color: rgb(255, 255, 0); ">for=</span><span style="color: rgb(187, 187, 0); ">&quot;email&quot;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&gt;&lt;small&gt;</span><span style="color: rgb(192, 192, 192); ">Mail (will not be published) </span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span>(<span style="color: rgb(204, 204, 0); ">$req</span>) <span style="color: rgb(255, 255, 0); font-weight: bold; ">echo</span> <span style="color: rgb(187, 187, 0); ">&quot;(required)&quot;</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/small&gt;&lt;/label&gt;&lt;/p&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;p&gt;&lt;input</span> <span style="color: rgb(255, 255, 0); ">type=</span><span style="color: rgb(187, 187, 0); ">&quot;text&quot;</span> <span style="color: rgb(255, 255, 0); ">name=</span><span style="color: rgb(187, 187, 0); ">&quot;url&quot;</span> <span style="color: rgb(255, 255, 0); ">id=</span><span style="color: rgb(187, 187, 0); ">&quot;url&quot;</span> <span style="color: rgb(255, 255, 0); ">value=</span><span style="color: rgb(187, 187, 0); ">&quot;</span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">echo</span> <span style="color: rgb(204, 204, 0); ">$comment_author_url</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span><span style="color: rgb(187, 187, 0); ">&quot;</span> <span style="color: rgb(255, 255, 0); ">size=</span><span style="color: rgb(187, 187, 0); ">&quot;22&quot;</span> <span style="color: rgb(255, 255, 0); ">tabindex=</span><span style="color: rgb(187, 187, 0); ">&quot;3&quot;</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">/&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;label</span> <span style="color: rgb(255, 255, 0); ">for=</span><span style="color: rgb(187, 187, 0); ">&quot;url&quot;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&gt;&lt;small&gt;</span><span style="color: rgb(192, 192, 192); ">Website</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/small&gt;&lt;/label&gt;&lt;/p&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">endif</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;p&gt;&lt;textarea</span> <span style="color: rgb(255, 255, 0); ">name=</span><span style="color: rgb(187, 187, 0); ">&quot;comment&quot;</span> <span style="color: rgb(255, 255, 0); ">id=</span><span style="color: rgb(187, 187, 0); ">&quot;comment&quot;</span> <span style="color: rgb(255, 255, 0); ">cols=</span><span style="color: rgb(187, 187, 0); ">&quot;100%&quot;</span> <span style="color: rgb(255, 255, 0); ">rows=</span><span style="color: rgb(187, 187, 0); ">&quot;10&quot;</span> <span style="color: rgb(255, 255, 0); ">tabindex=</span><span style="color: rgb(187, 187, 0); ">&quot;4&quot;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&gt;&lt;/textarea&gt;&lt;/p&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;p&gt;&lt;input</span> <span style="color: rgb(255, 255, 0); ">name=</span><span style="color: rgb(187, 187, 0); ">&quot;submit&quot;</span> <span style="color: rgb(255, 255, 0); ">type=</span><span style="color: rgb(187, 187, 0); ">&quot;submit&quot;</span> <span style="color: rgb(255, 255, 0); ">id=</span><span style="color: rgb(187, 187, 0); ">&quot;submit&quot;</span> <span style="color: rgb(255, 255, 0); ">tabindex=</span><span style="color: rgb(187, 187, 0); ">&quot;5&quot;</span> <span style="color: rgb(255, 255, 0); ">value=</span><span style="color: rgb(187, 187, 0); ">&quot;Submit Comment&quot;</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">/&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;input</span> <span style="color: rgb(255, 255, 0); ">type=</span><span style="color: rgb(187, 187, 0); ">&quot;hidden&quot;</span> <span style="color: rgb(255, 255, 0); ">name=</span><span style="color: rgb(187, 187, 0); ">&quot;comment_post_ID&quot;</span> <span style="color: rgb(255, 255, 0); ">value=</span><span style="color: rgb(187, 187, 0); ">&quot;</span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">echo</span> <span style="color: rgb(204, 204, 0); ">$id</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span><span style="color: rgb(187, 187, 0); ">&quot;</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">/&gt;&lt;/p&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(192, 192, 192); ">do_action</span>(<span style="color: rgb(187, 187, 0); ">&#39;comment_form&#39;</span><span style="color: rgb(192, 192, 192); ">,</span> <span style="color: rgb(204, 204, 0); ">$post</span><span style="color: rgb(192, 192, 192); ">-&gt;</span><span style="color: rgb(255, 255, 0); ">ID</span>); <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/form&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">endif</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">else</span> <span style="color: rgb(192, 192, 192); ">:</span> <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;p&gt;</span><span style="color: rgb(192, 192, 192); ">The comments are closed.</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/p&gt;</span>&nbsp; <br /> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">endif</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span></div>
<p>  这是WordPress 用来请求评论的函数。</p>
<p>整个流程就是这样，现在你拥有了自己的 comments.php 文件了，通过简单的修饰，你可以得到如下所示的效果：</p>
<p><a href="http://fvf.me/img/comment/1.jpg"><img title="comment1" alt="comment1" src="http://fvf.me/img/comment/1.jpg" /></a></p>
<h4 id="little-tricks">5. 一些小技巧</h4>
<p>毫无疑问，仅仅是一张 comments.php 文件，你就可以对它进行各种各样的改进，这里我列出一个表，希望能帮到你。</p>
<h5 id="gravatars">1. Gravatars</h5>
<p>从Wordpress2.5开始，Wordpress内置了对Gravatars头像的支持，这样Wordpress就可以方便的通过博客用户的邮箱地址来显示相关联头像。要实现这个效果的代码非常简单。</p>
<div class="source" style="font-family: 'Courier New', 'Lucida Console', Verdana; color: rgb(192, 192, 192); background-color: rgb(0, 0, 0); "> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">echo</span> <span style="color: rgb(192, 192, 192); ">get_avatar</span>(<span style="color: rgb(204, 204, 0); ">$author_email</span><span style="color: rgb(192, 192, 192); ">,</span> <span style="color: rgb(204, 204, 0); ">$size</span><span style="color: rgb(192, 192, 192); ">,</span> <span style="color: rgb(204, 204, 0); ">$default_avatar</span> ); <span style="color: rgb(255, 255, 255); ">?&gt;</span></div>
<p>在上述代码中，你可以把 $author_email 更换为 get_comment_author_email(); 函数，$size 则是头像的宽高，至于 $default_avatar 参数则是用来调用默认的头像，而且这个只在用户没有Gravatars头像时生效。</p>
<p>把上述代码插入评论的 foreach 循环。这样就可以输出 Gravatars 头像，该头像还有特定的评级以及大小（这完全取决于博客的设置），结合简单的CSS，你可以轻易的得到如下效果：</p>
<p><a href="http://fvf.me/img/comment/2.jpg"><img title="comment2" alt="comment2" src="http://fvf.me/img/comment/2.jpg" /></a></p>
<h5 id="comment-numbers">2. 评论数</h5>
<p>我特意把comments.php文件头部代码留在我们建立页面以后，因为我相信多余的代码会使学习过程变成复杂。当然了，我是不会忘记使用他们的。</p>
<p>通常，人们会看到一个类似于“迄今已经有3评论”，这要感谢wordpress提供了这么简单的模板标签。</p>
<div class="source" style="font-family: 'Courier New', 'Lucida Console', Verdana; color: rgb(192, 192, 192); background-color: rgb(0, 0, 0); "> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(192, 192, 192); ">comments_number</span>(<span style="color: rgb(204, 204, 0); ">$zero_comments</span><span style="color: rgb(192, 192, 192); ">,</span> <span style="color: rgb(204, 204, 0); ">$one_comment</span><span style="color: rgb(192, 192, 192); ">,</span> <span style="color: rgb(204, 204, 0); ">$more_comments</span>); <span style="color: rgb(255, 255, 255); ">?&gt;</span></div>
<p>不用说都明白：在显示的文本时$ zero_comments是，没有人发表评论， $ one_comment时有一个评论和$ more_comments当有多个评论。举个例子如下：</p>
<div class="source" style="font-family: 'Courier New', 'Lucida Console', Verdana; color: rgb(192, 192, 192); background-color: rgb(0, 0, 0); "> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(192, 192, 192); ">comments_number</span>(<span style="color: rgb(187, 187, 0); ">&#39;No comments&#39;</span><span style="color: rgb(192, 192, 192); ">,</span> <span style="color: rgb(187, 187, 0); ">&#39;One comment&#39;</span><span style="color: rgb(192, 192, 192); ">,</span> <span style="color: rgb(187, 187, 0); ">&#39;% comments&#39;</span>); <span style="color: rgb(255, 255, 255); ">?&gt;</span></div>
<p>我用％表示多少评论，因为comments_number功能能把%替换成（ 2 ， 3 ， ... ）</p>
<p>使用我们的comments.php文件，你可以轻易的得到如下效果：</p>
<p><a href="http://fvf.me/img/comment/3.jpg"><img title="comment3" alt="comment3" src="http://fvf.me/img/comment/3.jpg" /></a></p>
<h5 id="comment-links">3. 评论链接</h5>
<p>要显示一个链接的评论部分（或若干评论显示） ，只需使用以下代码</p>
<div class="source" style="font-family: 'Courier New', 'Lucida Console', Verdana; color: rgb(192, 192, 192); background-color: rgb(0, 0, 0); "> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(192, 192, 192); ">comments_popup_link</span>(<span style="color: rgb(204, 204, 0); ">$zero_comments</span><span style="color: rgb(192, 192, 192); ">,</span> <span style="color: rgb(204, 204, 0); ">$one_comment</span><span style="color: rgb(192, 192, 192); ">,</span> <span style="color: rgb(204, 204, 0); ">$more_comments</span><span style="color: rgb(192, 192, 192); ">,</span> <span style="color: rgb(204, 204, 0); ">$css_class</span><span style="color: rgb(192, 192, 192); ">,</span> <span style="color: rgb(204, 204, 0); ">$comments_closed</span>); <span style="color: rgb(255, 255, 255); ">?&gt;</span></div>
<p>前3个参数，功能同上述comments_number功能一样。 $ css_class，很显然这个标记CSS类，给链接&lt;a&gt;标记，$comments_closed是表示当时的评论已经关闭。</p>
<div class="source" style="font-family: 'Courier New', 'Lucida Console', Verdana; color: rgb(192, 192, 192); background-color: rgb(0, 0, 0); "> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(192, 192, 192); ">comments_popup_link</span>(<span style="color: rgb(187, 187, 0); ">&#39;No comments&#39;</span><span style="color: rgb(192, 192, 192); ">,</span> <span style="color: rgb(187, 187, 0); ">&#39;One comment&#39;</span><span style="color: rgb(192, 192, 192); ">,</span> <span style="color: rgb(187, 187, 0); ">&#39;% comments&#39;</span><span style="color: rgb(192, 192, 192); ">,</span> <span style="color: rgb(187, 187, 0); ">&#39;comments-link&#39;</span><span style="color: rgb(192, 192, 192); ">,</span> <span style="color: rgb(187, 187, 0); ">&#39;Comments are closed&#39;</span>); <span style="color: rgb(255, 255, 255); ">?&gt;</span></div>
<p>这就给你的链接加上了名为comments-link的class</p>
<h5 id="editing-comments">4. 编辑评论</h5>
<p>有时你会想到立即修改评论。幸运的是，运用edit_comment_link功能，您可以轻松地在网页中进行编辑，而不需要进到您的管理后台，以最终达成评论的目的。用法是这样的：</p>
<div class="source" style="font-family: 'Courier New', 'Lucida Console', Verdana; color: rgb(192, 192, 192); background-color: rgb(0, 0, 0); "> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(192, 192, 192); ">edit_comment_link</span>(<span style="color: rgb(204, 204, 0); ">$link_text</span><span style="color: rgb(192, 192, 192); ">,</span> <span style="color: rgb(204, 204, 0); ">$before_link</span><span style="color: rgb(192, 192, 192); ">,</span> <span style="color: rgb(204, 204, 0); ">$after_link</span>); <span style="color: rgb(255, 255, 255); ">?&gt;</span></div>
<p>你必须把这个代码放到foreach循环里面。参数是显而易见的： $ link_text是修改链接的锚文本， $ before_link和$ after_link分别是显示在之前或之后链接的文字或代码。</p>
<p>这样确实更容易修改评论，您可以只需添加一个小'编辑'链接到您的评论中（只能先以管理员的身份登录后） 。这就是它可以如下所示：</p>
<p><a href="http://fvf.me/img/comment/4.jpg"><img title="comment4" alt="comment4" src="http://fvf.me/img/comment/4.jpg" /></a></p>
<h5 id="alternate-rows">5. 评论的交互颜色</h5>
<p>可能您想要的您的评论交替行颜色变换，以达到更准确的分辨。这里有一种简单的方法。首先，将以下代码添加到网页顶部的：</p>
<div class="source" style="font-family: 'Courier New', 'Lucida Console', Verdana; color: rgb(192, 192, 192); background-color: rgb(0, 0, 0); "> <span style="color: rgb(255, 255, 0); font-weight: bold; ">function</span> <span style="color: rgb(192, 192, 192); ">alternate_rows</span>(<span style="color: rgb(192, 192, 192); ">$i</span><span style="color: rgb(192, 192, 192); ">){</span><span style="color: rgb(192, 192, 192); ">&lt;</span><span style="color: rgb(192, 192, 192); ">br</span> <span style="color: rgb(192, 192, 192); ">/&gt;</span>&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 255, 0); font-weight: bold; ">if</span>(<span style="color: rgb(192, 192, 192); ">$i</span> <span style="color: rgb(192, 192, 192); ">%</span> <span style="color: rgb(192, 192, 192); ">2</span>) <span style="color: rgb(192, 192, 192); ">{</span><span style="color: rgb(192, 192, 192); ">&lt;</span><span style="color: rgb(192, 192, 192); ">br</span> <span style="color: rgb(192, 192, 192); ">/&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(192, 192, 192); ">echo</span> <span style="color: rgb(187, 187, 0); ">&#39; class=&quot;alt&quot;&#39;</span>;<span style="color: rgb(192, 192, 192); ">&lt;</span><span style="color: rgb(192, 192, 192); ">br</span> <span style="color: rgb(192, 192, 192); ">/&gt;</span>&nbsp;&nbsp;&nbsp; <span style="color: rgb(192, 192, 192); ">}</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">else</span> <span style="color: rgb(192, 192, 192); ">{</span><span style="color: rgb(192, 192, 192); ">&lt;</span><span style="color: rgb(192, 192, 192); ">br</span> <span style="color: rgb(192, 192, 192); ">/&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(192, 192, 192); ">echo</span> <span style="color: rgb(187, 187, 0); ">&#39;&#39;</span>;<span style="color: rgb(192, 192, 192); ">&lt;</span><span style="color: rgb(192, 192, 192); ">br</span> <span style="color: rgb(192, 192, 192); ">/&gt;</span>&nbsp;&nbsp;&nbsp; <span style="color: rgb(192, 192, 192); ">}</span>&nbsp; <br /> <span style="color: rgb(192, 192, 192); ">}</span></div>
<p>然后添加以下到foreach循环内 。你可以查找&lt;li id="comment-&lt;?php comment_ID(); ?&gt;"&gt; ，然后用一下代码替换：</p>
<div class="source" style="font-family: 'Courier New', 'Lucida Console', Verdana; color: rgb(192, 192, 192); background-color: rgb(0, 0, 0); "> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(204, 204, 0); ">$i</span><span style="color: rgb(192, 192, 192); ">++</span>; <span style="color: rgb(255, 255, 255); ">?&gt;</span>&nbsp; <br /> <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;li</span> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(192, 192, 192); ">alternate_rows</span>(<span style="color: rgb(204, 204, 0); ">$i</span>); <span style="color: rgb(255, 255, 255); ">?&gt;</span> <span style="color: rgb(255, 255, 0); ">id=</span><span style="color: rgb(187, 187, 0); ">&quot;comment-</span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(192, 192, 192); ">comment_ID</span>(); <span style="color: rgb(255, 255, 255); ">?&gt;</span><span style="color: rgb(187, 187, 0); ">&quot;</span><span style="color: rgb(255, 255, 0); font-weight: bold; ">&gt;</span>&nbsp; <br /> <span style="color: rgb(255, 255, 0); font-weight: bold; ">&lt;/li&gt;</span></div>
<p>这将使评论出现两个不同的class ，从而可以通过CSS改变其外观 。<br />
我决定把它制成function，以减少对您实际主题文件的影响。您可以将它添加到您的函数定义functions.php文件里，但更有意义，对我来说，只是把它放到网页上面。<br />
交行更容易区分不同评论；一旦实施，您可能需要像这样：</p>
<p><a href="http://fvf.me/img/comment/5.jpg"><img title="comment5" alt="comment5" src="http://fvf.me/img/comment/5.jpg" /></a></p>
<h5 id="allowed-tags">6. 显示标签</h5>
<p>显示访问者可以在他们的意见使用的标签，只需使用以下的一段片段</p>
<div class="source" style="font-family: 'Courier New', 'Lucida Console', Verdana; color: rgb(192, 192, 192); background-color: rgb(0, 0, 0); "> <span style="color: rgb(192, 192, 192); ">Allowed tags: </span><span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(255, 255, 0); font-weight: bold; ">echo</span> <span style="color: rgb(192, 192, 192); ">allowed_tags</span>(); <span style="color: rgb(255, 255, 255); ">?&gt;</span></div>
<p>那么你一定会得到一个的名单，写着您可以在评论使用的标签，例如：</p>
<p><a href="http://fvf.me/img/comment/6.jpg"><img title="comment6" alt="comment6" src="http://fvf.me/img/comment/6.jpg" /></a></p>
<h5 id="comment-rss">7. 评论的RSS链接</h5>
<p>要获得链接RSS评论的地址，只需将下面的代码插入到您的comments.php文件中您想要的地方。</p>
<div class="source" style="font-family: 'Courier New', 'Lucida Console', Verdana; color: rgb(192, 192, 192); background-color: rgb(0, 0, 0); "> <span style="color: rgb(255, 255, 255); ">&lt;?php</span> <span style="color: rgb(192, 192, 192); ">comments_rss_link</span>(<span style="color: rgb(204, 204, 0); ">$link_text</span>); <span style="color: rgb(255, 255, 255); ">?&gt;</span></div>
<p>然后只需更换$ link_test为RSS链接的锚文本。</p>
<p>如果您想给您的访客有机会为某一特定的文章或博客帖子订阅评论的话，那这代码会派上用场。您可以得到以下效果：</p>
<p><a href="http://fvf.me/img/comment/7.jpg"><img title="comment7" alt="comment7" src="http://fvf.me/img/comment/7.jpg" /></a></p>
<h4 id="conclusion">6. 总结</h4>
<p>我希望你也很喜欢这个关于WordPress的comments.php文件的文章。你可以使用这里的全部代码，我的技巧包括在它表明：</p>
<p>gravatars ，</p>
<p>候补行的颜色，</p>
<p>编辑链接，</p>
<p>评论RSS链接。</p>
<p>显然，评论链接，因为这不包括已被用来内部循环 。</p>
<p>祝您在你的WordPress皮肤制作上有好运！</p>
<p>终于翻译完了！</p>
]]></content:encoded>
			<wfw:commentRss>http://fvf.me/translate/detailed-comment-php-production-template.html/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

