Separating Comments and Trackbacks
Some habits are hard to break. In the MT world - comments and trackbacks are different animals. Maybe just because I'm used to it that way - but that's the way I prefer it. A trackback/pingback isn't a complete thought. Comments (usually) are. When reading the comments section, I find it disrupting to see a trackback in the middle of the discussion. When I'm ready to leave the site and read another opinion, I will.
Ok, I'll get off the soapbox now. Greg asked me how I separated the comments and trackbacks on this site. Here's how:
Add the following function to your my-hacks.php file (See more information on how to use my-hacks.php here - link via Carthik) :
function return_comment_type($commenttxt = 'Comment', $trackbacktxt = 'Trackback', $pingbacktxt = 'Pingback') {
global $comment;
if (preg_match('|<trackback />|', $comment->comment_content))
return $trackbacktxt;
elseif (preg_match('|<pingback />|', $comment->comment_content))
return $pingbacktxt;
else
return $commenttxt;
}
And here's how you'll use it…
In wp-comments.php - this is what I have (edit for your own use as neccessary)
<?php if ($comments) { ?>
<?php
$cmts = 0;
$trkbks = 0;
?>
<p><b>:: Trackbacks/Pingbacks :: </b></p>
<ol>
<?php foreach ($comments as $comment) { ?>
<?php if (return_comment_type() != "Comment") { ?>
<?php $trkbks++; ?>
<a name="comment-<?php comment_ID() ?>"></a>
<li><?php comment_text() ?>
<p><?php comment_type(); ?> <?php _e("by"); ?> <?php comment_author_link() ?> — <?php comment_date() ?> <?php comment_time() ?> | <a href="#comment-<?php comment_ID() ?>">permalink</a></cite> <?php edit_comment_link(__("Edit This"), ' |'); ?></p>
<br />
</li>
<?php } ?>
<?php } // end for each comment ?>
</ol>
<?php if($trkbks <= 0) { ?>
<p>No Trackbacks/Pingbacks</p>
<?php } ?>
<p><b>:: Comments :: </b></p>
<ol>
<?php foreach ($comments as $comment) { ?>
<?php if (return_comment_type() == "Comment") { ?>
<?php $cmts++; ?>
<a name="comment-<?php comment_ID() ?>"></a>
<?php
// this is actually the "important" comment highlightling
$isImportant = false;
if (stristr($comment->comment_content, "<!–important–>")) {
$isImportant = true;
} ?>
<li>
<?php if($isImportant) { echo '<div class="importantcomment">';} ?>
<?php comment_text() ?>
<p><?php comment_type(); ?> <?php _e("by"); ?> <?php comment_author_link() ?> — <?php comment_date() ?> <?php comment_time() ?> | <a href="#comment-<?php comment_ID() ?>">permalink</a> <?php edit_comment_link(__("Edit This"), ' |'); ?></p>
<?php if($isImportant) { echo '</div>';} ?>
<br />
</li>
<?php } ?>
<?php } // end for each comment ?>
</ol>
<?php if($cmts <= 0) { ?>
<p>No comments</p>
<?php } ?>
<?php } else { // this is displayed if there are no comments so far ?>
<p><?php _e("No comments yet."); ?></p>
<?php } ?>
I should add that I'm not making any guarantees that this code will validate - feel free to edit for your own purpose.
(Updated to add: I'll probably want to combine this with this plugin I just found (via WxGal) which will give you a separate count for trackbacks and comments)
Post last updated: 6/22/04 9:27pm
June 21st, 2004 at 11:43 pm
Thanks so much. It worked perfectly. I agree with you on the comments/trackbacks thing. I want them separated also. It's disruptive to see trackbacks mixed into the comments… so thanks again for helping me out with this.
June 22nd, 2004 at 2:48 am
This is what I love about open source projects… great people willing to lend a hand to get things done.
June 22nd, 2004 at 5:41 pm
Well … looks like I've created my first, very own plugin for WordPress. The base install of WP gives you the option to have a comments popup. I was doing that on my MT blog, and wanted to do that here as well. Well, the default comments popup pag…
June 22nd, 2004 at 8:47 pm
June 22nd, 2004 at 9:41 pm
June 23rd, 2004 at 2:23 am
Do you need to separate your comments from your trackbacks? This hack from Scriptygoddess will do just that. Now you can have your trackbacks listed first and then your comments.
June 23rd, 2004 at 6:23 am
June 24th, 2004 at 2:55 pm
July 2nd, 2004 at 7:15 pm
I wanted to separate comments and trackbacks in individual entry posts. Not that a lot of people trackback to this site, but just in case someone did I didn't want it to get lost amongst the comments. So I found this hack at the Scriptygoddess site….
July 7th, 2004 at 8:01 pm
Rather than ping ScriptyGoddess multiple times and clog my sideblog with even more WordPress links, I decided to plop 'em all here. I'm going to give WordPress a try again on my course website, since there are various hacks that…
August 11th, 2004 at 1:29 am
August 11th, 2004 at 8:23 pm
August 12th, 2004 at 2:24 am
I redid how comments are displayed. There is now a nice clean display of the comments, so it's much easier to read. I used a nice little hack by scriptygoddess to separate the comments and trackbacks. So what are you waiting for? Comment away!
August 18th, 2004 at 5:31 pm
Jennifer,
From what you add in wp-comments.php, does this over-ride the original wp-comments.php or is this an addition?
August 18th, 2004 at 6:17 pm
nm, got it
August 19th, 2004 at 11:50 am
Well, I decided to go for it. I decided to move to Wordpress from Movable Type. I just couldn't stand it anymore — Wordpress is *fun*! All the plugins and hacks are cool, and I just love this Kubrick template by Michael Heilemann. And, the "Nice…
August 28th, 2004 at 11:29 am
August 28th, 2004 at 11:29 am
September 30th, 2004 at 2:34 pm
October 12th, 2004 at 12:58 pm
I have the same question as Chad since I don't know enough about programming…
What do I replace in wp-comments.php with what you have here? All or after the line?
Also, does each hack added in my-hacks.php begin and end with its own < ?php ?> set?
Thanks in advance
October 12th, 2004 at 1:00 pm
/
October 12th, 2004 at 1:15 pm
You're modifying the wp-comments.php page - where you see this:
<?php foreach ($comments as $comment) { ?>
all the way to this:
<p><?php _e("No comments yet."); ?></p>
<?php } ?>
You're replacing that whole block - with what i have above…
(FYI - if you're putting code into the comments box - you need to convert all the < > to their ascii equivalents. You should be able to select all your code and click the link in the text above the comment box that talks about doing this - and that will automatically convert your < > to ascii for you.)
October 12th, 2004 at 1:33 pm
After pasting in the code starting where you said <?php foreach and ending with ?> after the 'No comments section I get a Parse error. Unexpected $ in line 126.
Also, does each hack added in my-hacks.php begin and end with its own <?php ?> set?
November 11th, 2004 at 4:42 pm
I get the same problem as the fellow in the comment above (except mine says the unexpected $ is in line 128. Any idea how I've screwed up?
November 19th, 2004 at 7:40 am
I've used this hack on another blog before and it works perfectly. But with the blog I am working on now, I get this error on the comments page:
Fatal error: Call to undefined function: return_comment_type() in /home/emiline/public_html/daydreams/wp-comments.php on line 43
I know that has to do with the my-hacks file, but the my-hacks file is in the directory and I copied it straight from the my-hacks file I am using on the other blog that is working. Also the whole comments page is basically copied from the working blog, so I don't really understand why the code would work on one blog, but not on the other.
November 20th, 2004 at 2:55 am
Nevermind, I am stupid and forget I had to check the little box in the options panel to turn on the my hacks file. Duh.
January 5th, 2005 at 8:41 pm
January 24th, 2005 at 11:33 pm
Will you be updating this for v1.5 or will it still work without changes?
This is so awesome. I don't know why this isn't a default in WordPress. Nothing more frustrating that running across all the trackbacks within the comments!
January 25th, 2005 at 8:51 am
I'll probably have to update it. I'll add it to my to do list…