Trackbacks Woes
When I made the Feed Comments Number (awful name, I know) WP-Plugin, all sorts of sites picked up a link to my blog from “Newest WordPress Plugins” feeds, each of which creating a trackback comment. I didn’t want to turn trackbacks off, because I’d like to know when something like that happens (unless it gets insane and I get like hundreds of them for a post … which is highly unlikely), so I searched for a plugin to sort them out of the regular comments list. That turned up nothing that would work properly so I did it myself.
Now my theme will show the comments first, then a link showing how many trackback/pings are on that post that, when clicked, will display (un-hide) the list of trackback/pings.
For the interested, the code for the comments page (well, the important stuff) is shown below.
<ol> <?php foreach ($comments as $comment) : ?> <?php if(get_comment_type() == 'comment') { ?> <li class="<?php echo $oddcomment; ?> item" id="comment-<?php comment_ID() ?>"> <div class="commentmetadata"> <?php echo get_avatar( $comment, 48 ); ?> <strong><?php comment_author_link() ?></strong><br /> <small><a href="#comment-<?php comment_ID() ?>" title=""><?php comment_date('l, F j') ?> <?php comment_time() ?></a> </div> <div class="comment-body"><?php comment_text() ?></div> </li> <?php $oddcomment = ('alt' == $oddcomment) ? '' : 'alt'; } else { $num_trackbacks++; $trackbacks[] = $comment; } endforeach; /* end for each comment */ ?> </ol> <?php if(isset($num_trackbacks) && $num_trackbacks > 0) { ?> <p class="aligncenter"><a href="javascript:void(0)" onclick=" var el=document.getElementById('trackbacks'); if(el.style.display=='block') { el.style.display='none'; } else { el.style.display='block'; } " id="showTrackbacks"><?php echo $num_trackbacks; ?> Trackbacks/Pings Not Shown.</a></p> <ol id="trackbacks"> <?php foreach($trackbacks as $comment) { $oddcomment = ('alt' == $oddcomment) ? '' : 'alt'; ?> <li class="<?php echo $oddcomment; ?> item" id="comment-<?php comment_ID() ?>"> <div class="commentmetadata"> <strong><?php comment_author_link() ?></strong><br /> <small><a href="#comment-<?php comment_ID() ?>" title=""><?php comment_date('l, F j') ?> <?php comment_time() </div> <div class="comment-body"><?php comment_text() ?></div> </li> <?php } ?> </ol> <?php } ?>
Tuesday, December 23 12:29 am
Cool stuff. You plan to make this into a plugin?
Monday, December 29 12:38 am
It could be done. There are some that don’t work anymore that were made for older versions of WordPress that might be able to be salvaged, I don’t know.
It’s more of a theme enhancement thing to me. We shall see.
Leave a Comment