Over the last year and a bit Binary Moon has slowly evolved. Rather than redesign my site every few months I have chosen to update and improve as I go. Doing this I have added a few little features that I think are quite cool, so thought I would share my code in case you find it handy as well.
You have left a comment…
This ones easy. When people leave comments you want to show them a small message letting them know the comment is in moderation so that they don’t repost. All you have to do is, in your comment loop, add something like this:
<?php if ( $comment->comment_approved == '0' ) { ?>
<p class="alert">Thanks for your comment. It is currently in the moderation cue and will be visible for everyone to read as soon as I have verified it</p>
<?php } ?>
I must admit I find it a bit strange that this works, since I would have thought everyone would see the message, but it appears to work fine, so I’m not going to complain 🙂
Trackbacks and Comments
This one was also fairly simple to implement. I spent a bit of time Googling for ways to do this and ended up finding a couple of different techniques but the code on all of them was really untidy (sorry). I’m a big fan of beauty in code, not because I’m a geek (although I am) but because I find it makes the code easier to understand and maintain.
I ended up using the system on xmouse as a template for my code.
What you need to do is add the following code to functions.php (this is only available in wordpress 2.0 and greater – if you’re not using it I recommend you upgrade)
<?php
$bm_trackbacks = array();
$bm_comments = array();
function split_comments( $source ) {
if ( $source ) foreach ( $source as $comment ) {
global $bm_trackbacks;
global $bm_comments;
if ( $comment->comment_type == 'trackback' || $comment->comment_type == 'pingback' ) {
$bm_trackbacks[] = $comment;
} else {
$bm_comments[] = $comment;
}
}
} ?>
What the code is doing is looping through all the comments and splitting them into two new variables which are separately the comments and trackbacks for the post.
To use it you add the following before your comment loop:
<?php
global $bm_comments;
global $bm_trackbacks;
split_comments( $comments ); ?>
And then you can use the new comments the same way you always have:
<?php
// -----
// COMMENTS
// -----
foreach ( $bm_comments as $comment ) {
// comment display code (exactly the same as you use at the moment)
}
// ----
// TRACKBACKS
// ----
// check there actually are some trackbacks
if ( count( $bm_trackbacks ) > 0 ) {
// I like to add a separate heading here
foreach ( $bm_trackbacks as $comment ) { ?>
// trackback display code (I only display a link to the site and no message content)
}
}
?>
Now that I have typed all that out it looks a lot bigger and more complicated than I intended. Hopefully it’s clean enough for someone to get some use from it.
Query Post
WordPress has a command called query_posts that lets you do all sorts of groovy things with the site content. The query posts command is how I create my Recent Posts and Link Blog listings at the bottom of my homepage.
Your turn…
If you have any hints and tips for cool little features that you think would benefit my, or anyone elses, website then I’d love to hear them.
Was it good/ useful/ a load of old rubbish? Let me know on Mastodon, or BlueSky (or Twitter X if you must).
Link to this page
Thanks for reading. I'd really appreciate it if you'd link to this page if you mention it in your newsletter or on your blog.