29
WordPress Plugin Customization: Twitter Tools
6 Comments | Posted by Brent Danley in development, programming, twitter, web
Tweeting is nice because it’s terse; I can update my tweeps about what I’m doing, resources I’ve discovered and articles I’ve read between more lengthy and media-rich blog posts (and to publicize those posts).
The Twitter Tools plugin is a great way to integrate tweets into a WordPress blog. The most obvious benefit of this is that it keeps the content on the blog page fresh and allows bloggers to communicate bitlets of information that do not require their own post.
In addition to other worthwhile features, Twitter Tools allows a blog admin to display recent tweets in a sidebar widget, and to automatically publish tweets in a daily or weekly digest format. Twitter Tools caches tweets in a table of the WordPress database to reduce the number of calls to Twitter.
There were a few things about the plugin I didn’t particularly like out of the box. First, there was a link below the last tweet in the sidebar widget to take a visitor to my Twitter page. I prefer to have the widget title be that link. Second, the digest post title date format was ugly: “2009-06-29″ instead of “June 29, 2009″. Third, the link at the end of each tweet in the digest post had a simple ‘#’ instead of the date and time of the tweet, which also serves as a link to the original tweet.
To fix the first problem all I had to do was modify the title variable of the aktt_widget function. aktt_profile_url($aktt->twitter_username) returns the URL of my Twitter updates. $aktt->twitter_username holds is the username set in the plugin options. It would have been simpler to hard code my Twitter URL here, but that would have rendered the modified plugin importable, which is a major programming faux pas. This modification does ignore the title set in the plugin options.
function aktt_widget($args) { global $aktt; extract($args); $options = get_option('aktt_widget'); $title = '@<a href="'.aktt_profile_url($aktt->twitter_username).'">'.$aktt->twitter_username.'</a> on Twitter'; if (empty($title)) { } echo $before_widget . $before_title . $title . $after_title; aktt_sidebar_tweets(); echo $after_widget; }
To hide the “More updates…” link at the bottom of the sidebar widget I simply commented out the code which adds it.
/*if (!empty($aktt->twitter_username)) {
$output .= ' <li class="aktt_more_updates"><a href="'.aktt_profile_url($aktt->twitter_username).'">More updates...</a></li>'."\n";
}*/To fix the date format in the title of digest posts I simply found the array key which holds the post title and modified its value. Voila!
$post_data = array( 'post_content' => $wpdb->escape($content), 'post_title' => $wpdb->escape(sprintf($title, date('F j, Y'))), 'post_date' => date('Y-m-d H:i:s', $end), 'post_category' => array($this->blog_post_category), 'post_status' => 'publish', 'post_author' => $wpdb->escape($this->blog_post_author) );
The third problem was the most troublesome, but still pretty simple. Why the plugin developer chose to use a hash mark (#) instead of the date and time of the tweet as a link to the actual tweet is curious to me. The hash is not only not informative, but used to indicate keywords in tweets, which can be confusing.
Twitter Weekly Updates for May 24, 2009
There are certainly positive aspects of hot weather. RT @ccmaine: Today’s weather is begging for a sundress and [high heels] :) #
What is the date and time of the tweet above? This modification adds valuable information while preserving the ability to click on a hyperlink to visit the original tweet.
Twitter Weekly Updates for June 28, 2009
Excellent ideas to get creative juices flowing! RT @problogger: 100 Creative Twitter Backgrounds Featuring Illustration – http://is.gd/1fZCW 27 Jun 2009 @ 08:27
This is all done in a switch statement of the aktt_tweet_display function.
switch ($time) { case 'relative': $time_display = aktt_relativeTime($tweet->tw_created_at, 3); break; case 'absolute': $time_display = aktt_absoluteTime($tweet->tw_created_at); break; }
The value of the time_display variable was originally a boring '#'!
I borrowed code from the aktt_relativeTime function to write aktt_absoluteTime.
function aktt_absoluteTime ($date) { $time = gmmktime( substr($date, 11, 2) , substr($date, 14, 2) , substr($date, 17, 2) , substr($date, 5, 2) , substr($date, 8, 2) , substr($date, 0, 4) ); return date('j M Y @ H:i', $time); }
This simply takes the tweet time as a parameter and returns a formatted date string. Not too bad, eh?
Next I’ll have to modify the plugin to make mentions clickable. Or I can wait for the update, which will wipe out my customizations. :)
6 Comments for WordPress Plugin Customization: Twitter Tools
SHERYL | 20090916 at 22:50
Kim Lewis | 20090925 at 08:33
Hey Brent, above you stated that your solution to changing the appearence is modifying the CSS. What i want to do is change the left padding of the actual tweets (class=”aktt_tweets”) but can’t seem to find this class anywhere in the twitter-tools/twitter-tools.php file. My test environment is here: http://kim.synapticate.com/. Could you shed any light on how to change this margin? Thanks in advance!
Jen | 20090929 at 17:25
Were the changes for the date and from “#” to username for the tweets listed as a blog and not the widget? Not a pro at coding – want to make sure. Thanks
jxj | 20100221 at 01:55
Thanks for sharing. The code of the date part is exactly what I am looking for.



Can you change the formatting of Twitter Tools… I would love to frame the box that houses my tweets and have each tweet in it’s own framed box…..