How To: Add a Twitter Link to Your WordPress Blog

Twitter is all the rage these days and it doesn’t seem like it will be going anywhere any time soon.  With that said, it often surprises me that many WordPress blog owners  don’t offer a convenient way for their readers to retweet their content.  Anyone can grab a Twitter WordPress plugin to tweet their new content as it is published, but what about your older content?

Rather than passing up all that potential traffic, I’ve found that offering a link somewhere within your post (optimally at the bottom of each post) is a great way to help your readers and incoming search engine traffic to promote your content for you.  When people find great content they like to share it with others, so why not make it easy for them?

Not only is adding a “Tweet This!” link a great choice, but it is really easy to do.  Chances are if you do a search on Google for code to use you’ll find something like the following:

<a href="http://twitter.com/home?status=Currently reading <?php the_permalink(); ?>" title="Click to send this page to Twitter!" target="_blank">Tweet This!</a>

This code works just fine, but is not the most optimal solution in my opinion.  Depending on the permalink structure your WordPress blog uses, combined with the length of your domain name, it may be difficult to fit the link into a 140 character tweet.  It also doesn’t leave room for the person to add their own comments to the tweet.

As a proposed solution, I recommend using some WordPress code like the following:

<a href="http://twitter.com/home?status=RT @HackWordPress <?php the_title ();?> <?php echo get_settings('home'); ?>/?p=<?php the_ID(); ?>">Tweet This</a>

This code will automatically insert the “RT” and your Twitter account name (the above example uses our Twitter account, @HackWordPress) then use the ID form of your post with the tweet.  When people click the link in the tweet, they will then be redirected to the actual post using your blog’s selected permalink structure, making a convenient and typically short URL.

Have you integrated Twitter into your WordPress blog? Share your strategies in the comments!


Separating Trackbacks from Comments in WordPress 2.7+

Back when WordPress 2.7 was released, the WordPress team introduced a completely revamped comment form that included integration of threaded comments into the core software, introducing some dramatic changes with how comments are handled.   Unfortunately, this change broke one of the most popular comment hacks, separating trackbacks from comments.

Since then, several people have stepped up and shared some great hacks for separating trackbacks from comment in WordPress 2.7 or newer blogs .  So far the best guide I’ve found came from Sivel.net, which can be viewed here.  Click over and follow those steps get everything separated.

Note: The above guide is only for people using WordPress 2.7 or newer installations.  For people using WordPress 2.6 or earlier, you’ll want to use this tutorial.

Once you’ve got the comments successfully separated from the trackbacks, there are a couple additional tweaks you may want to do to clean up how things look (it really depends on preference I suppose).   The first is to clean up your trackbacks/pingbacks by only displaying the title instead of an excerpt and everything else.   In order to do this, you’ll need to find the following code in your comments.php file:

<ol>
<?php wp_list_comments('type=pings'); ?>

Now replace that code with the following:

<ol>
<?php wp_list_comments('type=pings&callback=list_pings'); ?>

Lastly, you’ll need to add the following code to your functions.php file (which can be created if you don’t already have one):

<?php
function list_pings($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;
?>
<li id="comment-<?php comment_ID(); ?>"><?php comment_author_link(); ?>
<?php } ?>

That should clean up the trackbacks/pingbacks section and you can also apply the same changes if you use a plugin to display tweetbacks.

The other thing you may want to do is fix the comment count to only show actual comments, filtering out the trackbacks/pingbacks which are included in your comment count by default.   Simply add the following code to your functions.php file (which again can be created if you don’t already have one):

<?php
add_filter('get_comments_number', 'comment_count', 0);
function comment_count( $count ) {
if ( ! is_admin() ) {
global $id;
$comments_by_type = &separate_comments(get_comments('status=approve&post_id=' . $id));
return count($comments_by_type['comment']);
} else {
return $count;
}
}
?>

So there you go.  Anyone have any other tips for cleaning up your comment form?


WordPress Theme Frameworks

Over a year ago, I was among those that speculated on custom widgets and their role in the future of WordPress themes.   One thing that wasn’t speculated on, however, was the rise of WordPress theme frameworks.  Now, just over a year later, many of the leaders in the premium themes market are building their own internal frameworks which are used as the backbone to design their premium WordPress themes.  For example, Woo Themes now has their own Woo Framework. Brian Gardner of StudioPress also recently informed me that he is also developing a framework for his StudioPress themes.

Premium theme designers are not the only ones using frameworks these days, however, and a few can actually be used by anyone in the development of their own personal themes! As with traditional WordPress themes, WordPress theme frameworks have free options, as well as paid alternatives. In the post below, I’ve collected the five major theme frameworks, and I intend to update this post as I learn of more WordPress theme frameworks.

Note: If these theme frameworks look a little plain, that is intentional.  Frameworks are designed for someone to use as a building point, so they lack a lot of images and design elements.   Once downloaded (or purchased), you can then build upon the framework to make your design.   Many of these frameworks also include child themes, which allow you to quickly convert your framework into a ready to use design.

WP Framework (FREE)

wp-framework

WP Framework is a blank WordPress theme framework by Ptah Dunbar, which aims to cut down on your theme development time. It gives you a solid theme foundation to build your project on top of so you can focus on project-specific features right from the git-go.

WP Framework | Live Demo

Thesis Theme Framework (Single-Use $87.00  | Developer’s Pack $164.00)

thesis-theme

The Thesis theme framework is the most popular theme framework which has a cost associated with it and has built a loyal cult following.   Among those followers are some very high profile WordPress sites built upon the Thesis framework, then customized for their personal needs.  You can look through a list of these clients on their homepage.

Among the reasons people love Thesis is their attention to SEO techniques and the complex control panel:

thesis-options

Thesis Theme | Live Demo

Know of a WordPress theme framework we are missing?  Please leave a comment or let us know about it!


How to: Use Thumbnails Generated by WordPress

One of ten brilliant tips that I shared yesterday, display images on your blog’s homepage without any custom fields or any additional functions.php script, something I first saw on WebDeveloperPlus.

How do you do it? First log in, on the sidebar select ‘Media’ (which is under ‘Settings’). You’ll then be taken to a page with an option to change the thumbnail size of images. Change that to whatever size you want your images to appear as. Next, insert the code below onto your homepage, archive page, whatever.

<?php
//Get images attached to the post
$args = array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'numberposts' => -1,
'order' => 'ASC',
'post_status' => null,
'post_parent' => $post->ID
);
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $attachment) {
$img = wp_get_attachment_thumb_url( $attachment->ID );
break; }
//Display image
} ?>

Then, to display your image you can just echo out the $img tag we just created:

<img src="<?php echo $img; ?>" alt=" " />


Follow WordPress Hacks on Twitter!

Based upon the emails we get each month from readers who are trying to find our Twitter feed, I feel this post is probably long overdue, but I wanted to point out to our readership that we do in fact have a Twitter page!   If you’d like to follow WPHacks.com on Twitter, you can get our updates here (@HackWordPress). 

Our Twitter feed includes notification each time we publish a post here on WPHacks.com, but as an added bonus, you will also get some retweets of our favorite WordPress-related content published by others. 

Note:  If you’d like to follow my personal tweets also, you can do so here.  (@KyleEslick)