<?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>Fri, 03 Feb 2012 05:37:11 +0000</lastBuildDate>
	<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>admin_mwc</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>
<p>There are 2 flaws with the code above.&#8230; <a href="http://www.maverickwebcreations.com/2008/10/19/separate-wordpress-comments-trackbacks-trackback-counter.html" class="read_more">Read more...</a></p>
It does not display the number of trackbacks in the]]></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>
<pre class="brush: php; title: ; notranslate">
&lt;?php foreach ($comments as $comment) : ?&gt;
&lt;?php $comment_type = get_comment_type(); ?&gt;
&lt;?php if($comment_type == 'comment') { ?&gt;
&lt;?php } else { $trackback = true; }  ?&gt;
&lt;?php endforeach; ?&gt;
&lt;?php if ($trackback == true) { ?&gt;
&lt;h3&gt;Trackbacks&lt;/h3&gt;
&lt;ol&gt;
&lt;?php foreach ($comments as $comment) : ?&gt;
&lt;?php $comment_type = get_comment_type(); ?&gt;
&lt;?php if($comment_type != 'comment') { ?&gt;
&lt;li&gt;&lt;?php comment_author_link() ?&gt;&lt;/li&gt;
&lt;?php } ?&gt;
&lt;?php endforeach; ?&gt;
&lt;/ol&gt;
&lt;?php } ?&gt;
</pre>
<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>
<pre class="brush: php; title: ; notranslate">
&lt;?php
#COMMENTS EXIST
if($comments)
{
	#INITIALIZE COMMENT &amp; TRACKBACK STATUS
	$comment_status = false;
	$trackback_status = false;
	#INITIALIZE COMMENTS COUNTER
	$comments_counter = 0;
	#INITIALIZE TRACKBACK COUNTER
	$trackback_counter = 0;
	#DETERMINE COMMENT &amp; TRACKBACK STATUS
	foreach($comments as $comment)
	{
		#RETRIEVE COMMENT TYPE
		$comment_type = get_comment_type();
		#COMMENT TYPE IS COMMENT
		if($comment_type == 'comment')
		{
			#COMMENTS EXIST
			$comment_status = true;
			#INCREMENT COMMENTS COUNTER
			$comments_counter ++;
		}
		#COMMENT TYPE IS TRACKBACK
		else
		{
			#TRACKBACKS EXIST
			$trackback_status = true;
			#INCREMENT TRACKBACK COUNTER
			$trackback_counter ++;
		}
	}
</pre>
<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>
<pre class="brush: php; title: ; notranslate">
	#DISPLAY COMMENTS
	if($comment_status)
	{
	?&gt;
		&lt;a name=&quot;comments&quot;&gt;&lt;/a&gt;&lt;h3 class=&quot;comment_title&quot;&gt;&lt;?php if($comments_counter == 1) { echo &quot;$comments_counter Comment&quot;; } else { echo &quot;$comments_counter Comments&quot;;  } ?&gt; On &amp;#8220;&lt;?php the_title(); ?&gt;&amp;#8221;&lt;/h3&gt;
		&lt;div id=&quot;comment_block&quot;&gt;
		&lt;?php
		#DISPLAY COMMENTS
		foreach($comments as $comment)
		{
			#RETRIEVE COMMENT TYPE
			$comment_type = get_comment_type();
			#COMMENT TYPE IS COMMENT
			if($comment_type == 'comment')
			{
			?&gt;
ADD YOUR OWN CODE HERE!
			&lt;?php
			}
		}
		?&gt;
		&lt;/div&gt;
	&lt;?php
	}
}
</pre>
<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>
<pre class="brush: php; title: ; notranslate">
#TRACKBACKS EXIST
if($trackback_status)
{
?&gt;
	&lt;h3 class=&quot;comment_title&quot;&gt;&lt;?php if($trackback_counter == 1) { echo &quot;$trackback_counter Trackback&quot;; } else { echo &quot;$trackback_counter Trackbacks&quot;;  } ?&gt; On &amp;#8220;&lt;?php the_title(); ?&gt;&amp;#8221;&lt;/h3&gt;
	&lt;div id=&quot;comment_block&quot;&gt;
		&lt;ol&gt;
		&lt;?php
		#DISPLAY COMMENTS
		foreach($comments as $comment)
		{
			#RETRIEVE COMMENT TYPE
			$comment_type = get_comment_type();
			#COMMENT TYPE IS TRACKBACK
			if($comment_type != 'comment')
			{
			?&gt;
			&lt;li&gt;&lt;?php comment_author_link() ?&gt;&lt;/li&gt;
			&lt;?php
			}
		}
		?&gt;
		&lt;/ol&gt;
	&lt;/div&gt;
&lt;?php
}
</pre>
<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>9</slash:comments>
		</item>
	</channel>
</rss>

