Separating Trackbacks and Comments in WordPress 2.7+

Interested in separating your trackbacks and comments on your WordPress blog?   This blog tutorial should have you covered, whether you use a modern WordPress installation, or an older (pre 2.7) version of WordPress.   Below you’ll find we’ve put together a tutorial for both types of comment loops.

For WordPress 2.7+ Installations

Locate the following code in your index.php or single.php file (whichever file your theme uses to show single post pages):

<?php comments_template(); ?>

Replace that code with the following:

<?php comments_template('', true); ?>

That is it for that file.   Now go to your comments.php file and locate the following code:

<?php if ( have_comments() ) : ?>

Immediately below that code, insert the following code:

<?php if ( ! empty($comments_by_type['comment']) ) : ?>

Okay, once that is done, you’ll next need to scroll down a little further (still in the comments.php file) and locate the following code:

<?php wp_list_comments(); ?>

You’ll want to replace that code with the below code:

<?php wp_list_comments('type=comment'); ?>

Immediately below this function you should see the following code:

</ol>

Directly below that code, place the following code:

<?php endif; ?>

That should take care of the comment loop.  The last step is to insert the code which will display the trackbacks/pingbacks.  This can be placed anywhere below the code we just hacked above:

<?php if ( ! empty($comments_by_type['pings']) ) : ?>
<h3 id="pings">Trackbacks/Pingbacks</h3>
<ol>
<?php wp_list_comments('type=pings'); ?>
</ol>
<?php endif; ?>

Some people prefer to display their trackbacks and pingbacks below the comment form or somewhere else out of the way, so this is really up to you!  Just place the above code where you want to show them.   If you don’t like them showing at all on your blog, just don’t place the above code at all.

Once that is done, it is time to give it a try.  Check it out on your blog and let us know how everything turns out!

For Pre-WordPress 2.7 Installations:

Prior to WordPress 2.7, the comment form wasn’t nearly as functional as it is with the newer versions and also included a lot more code, but it is still possible to separate the trackbacks and comments using the old comment loop.     If you’d like to separate your trackbacks from your comments on a WordPress 2.6 or earlier installation, here is the steps you’ll need to take.

First, access your comments.php file and grab the following code:

<?php foreach ($comments as $comment) : ?>

Immediately after the above code, you’ll want to place the following code:

<?php $comment_type = get_comment_type(); ?>
<?php if($comment_type == 'comment') { ?>

Next, scroll down a little bit and locate the following code:

<?php endforeach; /* end for each comment */ ?>

Immediately before the above code, you’ll want to place this code:

<?php } /* End of is_comment statement */ ?>

This will filter out all of the trackbacks and pingbacks from your main comments loop. Now we need to create a second comments loop to display the trackbacks and pingbacks.  Almost immediately below the code from step 2 you should find this code:

<?php else : // this is displayed if there are no comments so far ?>

Immediately before the above code, you’ll want to place this code:

<h3>Trackbacks</h3>
<ol>
<?php foreach ($comments as $comment) : ?>
<?php $comment_type = get_comment_type(); ?>
<?php if($comment_type != 'comment') { ?>
<li><?php comment_author_link() ?></li>
<?php } ?>
<?php endforeach; ?>
</ol>

You can adjust this code to display how you want to, including using a different header if you have a specific look for your header 3.

If you’ve tried this tutorial, let us know how it worked for you in the comments!

Code: Display Last Modified Date in WordPress

If you run a website or blog professionally, it is always good business practice to update your older posts to keep them as valid and current as possible.   This helps retain (or even grow) their search engine positions, and helps keep your blog from having dead links or outdated content. 

One of the things I recommend readers do on these types of blogs which use WordPress is to adjust the date field to instead show the last modified date.   This way posts that were written two years ago won’t have that date if you’ve updated them more recently!

Here is the code you’ll need to easily accomplish this.   As always, you’ll want to make a backup of your single.php file (or any files you will be changing) before proceeding.

[Read more...]

How-To: Display Most Recent Twitter Entry on Your WordPress Blog

Proud of your tweets?   Maybe you run a business blog and would like to integrate your Twitter feed?   For WordPress users, adding your most recent tweet to your WordPress blog is actually very easy.   Simply add a little code snippet in your blog’s sidebar where you want to display your most recent tweet, then add your Twitter username!

Here is the code you’ll need to easily add the most recent Twitter entry: [Read more...]

Code: Adding Edit Buttons to WordPress

There are a growing number of premium themes on the market these days for WordPress users, many of which are extremely advanced, yet I’ve found that many designers fail to add some of the most basic things all themes should have.  One of the things many designers forget to do is code ”edit” buttons on their posts, pages, and comments.  

For those unfamilar with these buttons, they only show up for people who are logged into the admin panel (readers can’t see them).   When clicked, you are routed directly to the post/page or comment within the admin panel so you can edit the post.   It has been my experience that having access to these buttons can save a lot of time when trying to manage and update older posts. 

[Read more...]

Code: Display Categories and Archives in WordPress

There has been some debate by bloggers over the past few years as to the value of displaying your archives, with some bloggers going as far as to not even display their categories!    The general idea is that the use of recent posts, popular posts, and a built-in search feature will allow your readers to find what they are looking for.

Well, I for one still believe that categories and archives should be displayed on blogs.   If you’d like to do the same for a WordPress blog, here is the code you’ll want to use.   For your convenience, we’ve provided two options for each:  traditional display and drop-down menus.

Simply paste the WordPress code below in your sidebar.php file where you want the category or archives to display: [Read more...]