<?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>Maverick Web Creations &#187; trackback</title>
	<atom:link href="http://www.maverickwebcreations.com/tag/trackback/feed" rel="self" type="application/rss+xml" />
	<link>http://www.maverickwebcreations.com</link>
	<description></description>
	<lastBuildDate>Thu, 29 Jul 2010 06:34:05 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Separate WordPress Comments and Trackbacks Plus a Trackback Counter</title>
		<link>http://www.maverickwebcreations.com/2008/10/19/separate-wordpress-comments-trackbacks-trackback-counter.html</link>
		<comments>http://www.maverickwebcreations.com/2008/10/19/separate-wordpress-comments-trackbacks-trackback-counter.html#comments</comments>
		<pubDate>Sun, 19 Oct 2008 00:00:54 +0000</pubDate>
		<dc:creator>Vincent</dc:creator>
				<category><![CDATA[Wordpress Help]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[blogging]]></category>
		<category><![CDATA[comments]]></category>
		<category><![CDATA[pingback]]></category>
		<category><![CDATA[trackback]]></category>
		<category><![CDATA[WordPress]]></category>
		<guid isPermaLink="false">http://www.maverickwebcreations.com/?p=254</guid>
		<description><![CDATA[<p>I have read numerous tutorials online about displaying WordPress comments and trackbacks separately. Most of the tutorials seem to be carbon copies of each other and it probably looks something like this&#8230;</p>
<div class="wp_syntax">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17</div><p>&#8230; <a href="http://www.maverickwebcreations.com/2008/10/19/separate-wordpress-comments-trackbacks-trackback-counter.html" class="read_more">Read more...</a></p>]]></description>
			<content:encoded><![CDATA[<p>I have read numerous tutorials online about displaying WordPress comments and trackbacks separately. Most of the tutorials seem to be carbon copies of each other and it probably looks something like this&#8230;</p>
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</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: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$comments</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$comment</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$comment_type</span> <span style="color: #339933;">=</span> get_comment_type<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$comment_type</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'comment'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$trackback</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>  <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endforeach</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$trackback</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;h3&gt;Trackbacks&lt;/h3&gt;
&lt;ol&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$comments</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$comment</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$comment_type</span> <span style="color: #339933;">=</span> get_comment_type<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$comment_type</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'comment'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;li&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> comment_author_link<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&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>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endforeach</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/ol&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>There are 2 flaws with the code above.</p>
<ol>
<li>It does not display the number of trackbacks in the trackbacks header</li>
<li>It does not hide the comments header if there are only trackbacks</li>
</ol>
<p>I have addressed the 2 issues in my code and here&#8217;s my WordPress theme&#8217;s comments.php:</p>
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
</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: #666666; font-style: italic;">#COMMENTS EXIST
</span><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$comments</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">#INITIALIZE COMMENT &amp; TRACKBACK STATUS
</span>	<span style="color: #000088;">$comment_status</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$trackback_status</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">#INITIALIZE COMMENTS COUNTER
</span>	<span style="color: #000088;">$comments_counter</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">#INITIALIZE TRACKBACK COUNTER
</span>	<span style="color: #000088;">$trackback_counter</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">#DETERMINE COMMENT &amp; TRACKBACK STATUS
</span>	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$comments</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$comment</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">#RETRIEVE COMMENT TYPE
</span>		<span style="color: #000088;">$comment_type</span> <span style="color: #339933;">=</span> get_comment_type<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">#COMMENT TYPE IS COMMENT
</span>		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$comment_type</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'comment'</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">#COMMENTS EXIST
</span>			<span style="color: #000088;">$comment_status</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">#INCREMENT COMMENTS COUNTER
</span>			<span style="color: #000088;">$comments_counter</span> <span style="color: #339933;">++;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #666666; font-style: italic;">#COMMENT TYPE IS TRACKBACK
</span>		<span style="color: #b1b100;">else</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">#TRACKBACKS EXIST
</span>			<span style="color: #000088;">$trackback_status</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">#INCREMENT TRACKBACK COUNTER
</span>			<span style="color: #000088;">$trackback_counter</span> <span style="color: #339933;">++;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>
<p>What this code does it looks through all the comments of a particular post to find both comments and trackbacks. I declared a trackback counter variable at the top to count the number of trackbacks, which we will use in another code segment. Whenever a trackback has been detected, we add 1 to the trackback counter variable.</p>
<p>I also want to know if there are any comments for a post. WordPress considers both trackbacks and comments as comments. In this context, we want to consider them as 2 separate things. Therefore, I created variables to check if there are any comments and trackbacks. Sometimes you may have a bunch of trackbacks but no comments. The other guys didn&#8217;t write their code to cater for this situation.</p>
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">	#DISPLAY COMMENTS
	if($comment_status)
	{
	?&gt;
		&lt;a name=&quot;comments&quot;&gt;&lt;/a&gt;&lt;h3 class=&quot;comment_title&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$comments_counter</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$comments_counter</span> Comment&quot;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$comments_counter</span> Comments&quot;</span><span style="color: #339933;">;</span>  <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> On &amp;#8220;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&amp;#8221;&lt;/h3&gt;
&nbsp;
		&lt;div id=&quot;comment_block&quot;&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span>
		<span style="color: #666666; font-style: italic;">#DISPLAY COMMENTS
</span>		<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$comments</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$comment</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">#RETRIEVE COMMENT TYPE
</span>			<span style="color: #000088;">$comment_type</span> <span style="color: #339933;">=</span> get_comment_type<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">#COMMENT TYPE IS COMMENT
</span>			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$comment_type</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'comment'</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">?&gt;</span>
ADD YOUR OWN CODE HERE!
			<span style="color: #000000; font-weight: bold;">&lt;?php</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">?&gt;</span>
		&lt;/div&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>
<p>The code above displays the comments only if they exist. Please use your existing code to display the comments. I left my code blank at that portion because my templates display comments slightly differently.</p>
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">#TRACKBACKS EXIST
if($trackback_status)
{
?&gt;
	&lt;h3 class=&quot;comment_title&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$trackback_counter</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$trackback_counter</span> Trackback&quot;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$trackback_counter</span> Trackbacks&quot;</span><span style="color: #339933;">;</span>  <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> On &amp;#8220;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&amp;#8221;&lt;/h3&gt;
&nbsp;
	&lt;div id=&quot;comment_block&quot;&gt;
		&lt;ol&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span>
		<span style="color: #666666; font-style: italic;">#DISPLAY COMMENTS
</span>		<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$comments</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$comment</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">#RETRIEVE COMMENT TYPE
</span>			<span style="color: #000088;">$comment_type</span> <span style="color: #339933;">=</span> get_comment_type<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">#COMMENT TYPE IS TRACKBACK
</span>			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$comment_type</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'comment'</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">?&gt;</span>
			&lt;li&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> comment_author_link<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/li&gt;
			<span style="color: #000000; font-weight: bold;">&lt;?php</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">?&gt;</span>
		&lt;/ol&gt;
	&lt;/div&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>
<p>The code above displays all the trackbacks in an ordered list. Furthermore, I added a header with a counter. The counter will display 1 Trackback if there is only 1 trackback or X Trackbacks if there is more than one trackback.</p>
<p>That&#8217;s all there is to this! Try this out on your WordPress blog and let me know your comments about it. I would be happy to get your ideas on how to improve it further.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.maverickwebcreations.com/2008/10/19/separate-wordpress-comments-trackbacks-trackback-counter.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
