scriptygoddess

21 Jun, 2004

Separating Comments and Trackbacks

Posted by: Jennifer In: WordPress my-hacks additions

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

29 Responses to "Separating Comments and Trackbacks"

1 | Binary Bonsai » Minor SQL problems and an update

June 22nd, 2004 at 8:47 pm

Avatar

[…] , where the comments have been segregated from the track- and pingbacks. It's all based on Scriptygoddess's plugin. It still needs some minor adjustme […]

2 | WxGal's World :: Journal » Trackback popup plugin

June 22nd, 2004 at 9:41 pm

Avatar

[…] Well, in order to get ONLY the comments to show up on the comment popup page, I used the code that Scriptygoddess had for separating […]

3 | Blogging Pro - Blog News, Tools and Hacks » WordPress Hack: Separating Comments & Trackbacks

June 23rd, 2004 at 6:23 am

Avatar

[…] ess Hacks|Google it! Do you need to separate your comments from your trackbacks? This hack from Scriptygoddess will do just that. Now you can hav […]

4 | Weblog Tools Collection » scriptygoddess: Seperate comments and trackbacks

June 24th, 2004 at 2:55 pm

Avatar

[…] ts and trackbacks Filed under: WordPress Hack LinkyLoo — Mark @ 10:55 am Scriptygoddess: Seperate comments and trackbacks: If you ha […]

5 | berto vive no mundo » Organizando os comentários en wordpress

August 11th, 2004 at 1:29 am

Avatar

[…] /das visitantes" "Este post foi mencionado en" Para esto baseime nun artigo de scriptygoddess cunhas cantas modificacións pola […]

6 | Linkkivarasto » WordPressin säätöä #2

August 11th, 2004 at 8:23 pm

Avatar

[…] DewVirus WordPress Plugins And Hacks (sisältää Comment Count ja Most Commented -pluginit), kommentit ja trackbackit erottava plugin, moderointi yli vi […]

7 | noscope | Colophon and other Updates

August 28th, 2004 at 11:29 am

Avatar

[…] it. The permalink is still available if you click the number next to the comment. Using Scriptygoddess' technique, I have separated comments […]

8 | noscope | Colophon and other Updates

August 28th, 2004 at 11:29 am

Avatar

[…] it. The permalink is still available if you click the number next to the comment. Using Scriptygoddess' technique, I have separated comments […]

9 | lite pollution » separating comment types

September 30th, 2004 at 2:34 pm

Avatar

[…] 217;s a small thing, but it makes things a bit cleaner. Thanks to scriptygoddess for this excellent hack. […]

10 | Zootropo. Diario del Mundo Geek » Pequeños cambios

January 5th, 2005 at 8:41 pm

Avatar

[…] costumbre de tratar como si fueran lo mismo, utilizando para ello una pequeña función de Scripty Goddess. […]

11 | Greg

June 21st, 2004 at 11:43 pm

Avatar

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.

12 | Plays Well With Others

June 22nd, 2004 at 2:48 am

Avatar

ScriptyGoddess To The Rescue…
This is what I love about open source projects… great people willing to lend a hand to get things done.

13 | WxGal's World :: Journal

June 22nd, 2004 at 5:41 pm

Avatar

Trackback popup plugin
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…

14 | Blogging Pro - Blog News, Tools and Hacks

June 23rd, 2004 at 2:23 am

Avatar

WordPress Hack: Separating Comments & Trackbacks
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.

15 | typedby.com

July 2nd, 2004 at 7:15 pm

Avatar

Separating Comments and Trackbacks
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….

16 | Mama Write

July 7th, 2004 at 8:01 pm

Avatar

Various WordPress Links
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…

17 | cavemonkey50.com v2.5

August 12th, 2004 at 2:24 am

Avatar

Mini Update
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!

18 | Chad Evans

August 18th, 2004 at 5:31 pm

Avatar

Jennifer,

From what you add in wp-comments.php, does this over-ride the original wp-comments.php or is this an addition?

19 | Chad Evans

August 18th, 2004 at 6:17 pm

Avatar

nm, got it

20 | Rippleweb

August 19th, 2004 at 11:50 am

Avatar

I Took The Plunge
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…

21 | William Meisheid

October 12th, 2004 at 12:58 pm

Avatar

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

22 | William Meisheid

October 12th, 2004 at 1:00 pm

Avatar

/

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements