<?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>Milo&#039;s Blog &#187; 评论结构</title>
	<atom:link href="http://imilo.net/blog/tag/%e8%af%84%e8%ae%ba%e7%bb%93%e6%9e%84/feed/" rel="self" type="application/rss+xml" />
	<link>http://imilo.net/blog</link>
	<description>Learn to enjoy your life!</description>
	<lastBuildDate>Thu, 15 Jul 2010 01:38:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>如何改造WordPress的评论结构</title>
		<link>http://imilo.net/blog/2009/12/30/reform-wp-comments-structure/</link>
		<comments>http://imilo.net/blog/2009/12/30/reform-wp-comments-structure/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 05:22:21 +0000</pubDate>
		<dc:creator>Milo</dc:creator>
				<category><![CDATA[Work]]></category>
		<category><![CDATA[主题]]></category>
		<category><![CDATA[评论结构]]></category>

		<guid isPermaLink="false">http://imilo.net/blog/?p=68</guid>
		<description><![CDATA[昨天有同学问我新主题的评论结构是怎么改的。 其实要更改评论的结构并不难，首先你要先了解wp_list_comments()这个函数。自WordPress更新至2.7版本起，由于其原生支持了嵌套评论(Threaded Comments)功能，故引入了一个新的内核函数wp_list_comments()，这个函数用于显示整个评论列表，能够根据用户的评论层次自动进行嵌套显示。因为wp_list_comments()封装了评论的相关代码，对于一些想要个性化样式评论的朋友来说，仅仅使用WordPress的默认结构显然不够用了。 下图是wp_list_comments()默认的代码结构： 为了修改评论的结构，我们需要用到wp_list_comments()的callback参数。首先找到comments.php中的wp_list_comments()函数，更改如下： 1 &#60;?php wp_list_comments&#40;'type=comment&#38;callback=custom_comments'&#41;;?&#62; type=comment：表示需要提取的内容为评论，因为wp_list_comments()提取的对象不仅仅有评论还有引用通告 callback=custom_comments：表示我要使用我自己的评论显示函数custom_comments()，这个函数的名字可以自己定义 自己的函数名确定后，找到functions.php文件，建立自己的评论显示函数，代码如下： 1 2 3 4 5 6 &#60;?php function custom_comments&#40;$comment, $args, $depth&#41; &#123; $GLOBALS&#91;'comment'&#93; = $comment; ?&#62; &#60;li&#62;&#60;/li&#62;&#60;?php &#125; ?&#62; 最后在li标签之间添加自己定制化的HTML代码结构就搞定了。]]></description>
			<content:encoded><![CDATA[<p>昨天有同学问我新主题的评论结构是怎么改的。</p>
<p>其实要更改评论的结构并不难，首先你要先了解wp_list_comments()这个函数。自WordPress更新至2.7版本起，由于其原生支持了嵌套评论(Threaded Comments)功能，故引入了一个新的内核函数wp_list_comments()，这个函数用于显示整个评论列表，能够根据用户的评论层次自动进行嵌套显示。因为wp_list_comments()封装了评论的相关代码，对于一些想要个性化样式评论的朋友来说，仅仅使用WordPress的默认结构显然不够用了。</p>
<p>下图是wp_list_comments()默认的代码结构：<br />
<img class="alignnone size-full wp-image-70 marginTopA" title="Default-Comment" src="http://imilo.net/blog/wp-content/uploads/2009/12/Default-Comment.jpg" alt="Default-Comment" width="500" height="250" /><span id="more-68"></span></p>
<p>为了修改评论的结构，我们需要用到wp_list_comments()的callback参数。首先找到comments.php中的wp_list_comments()函数，更改如下：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_list_comments<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'type=comment&amp;callback=custom_comments'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<ol class="marginTopB">
<li>type=comment：表示需要提取的内容为评论，因为wp_list_comments()提取的对象不仅仅有评论还有引用通告</li>
<li>callback=custom_comments：表示我要使用我自己的评论显示函数custom_comments()，这个函数的名字可以自己定义</li>
</ol>
<p>自己的函数名确定后，找到functions.php文件，建立自己的评论显示函数，代码如下：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #000000; font-weight: bold;">function</span> custom_comments<span style="color: #009900;">&#40;</span><span style="color: #000088;">$comment</span><span style="color: #339933;">,</span> <span style="color: #000088;">$args</span><span style="color: #339933;">,</span> <span style="color: #000088;">$depth</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$GLOBALS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'comment'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$comment</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;li&gt;&lt;/li&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>最后在li标签之间添加自己定制化的HTML代码结构就搞定了。</p>
]]></content:encoded>
			<wfw:commentRss>http://imilo.net/blog/2009/12/30/reform-wp-comments-structure/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
	</channel>
</rss>
