Web Development

Did I Miss The Boat With Twitter?05 Oct

I don’t think so! I just signed up as a way to basically have something to text about on my phone. I seem to text so infrequently, and I have unlimited texting! So the most obvious way to spend waste my time effectively, is with Twitter! So now I have yet another reason to burn my thumbs out with my phone.

This of course, brings me to another point, and therefore, the whole point of this article. I realized that with this new functionality, that I needed to integrate it into my site. Well, being that I am working with WordPress, and an obvious fan, the solution was easy – or so I thought. I began researching to see if anyone has created Twitter plug-ins available for direct integration into WordPress. I found a couple, but nothing seemed to work well with the K2platform. It was at this point, that I knew some plug-in creation/manipulation was going to be required in getting this one right.

I ended up downloading a plug-in base called MyTwitter. This gave fairly basic functionality for displaying tweetsas they are called in the biz! I knew that I needed to integrate this into my sidebar, and since K2 offers dynamic sidebar control, it was only a matter of getting the plug-in recognized, configured, and presto, it would work! Well that wasn’t quite the way it went. I first noticed that with my custom style, the code behind MyTwitter was creating erroneous <li> elements before and after the outer <ul> wrappers. This essentially was breaking my CSS by overriding the styling controls I had previously defined. To counter this, I had to modify the source file mytwitter.phpwhich is found in the root of the plug-in folder. This is the main output and polling page for the plug-in, with a second file mytwitter_admin.phpfor the back-end configuration. Here are the modifications made in the mytwitter.php page:

Line 95
echo "<div id=\"twitter\"><h4 class=\"widgettitle\"><a href='" . $my_twitter . "' title='view my twitters'>" . $title . "</a></h4>\n"; //display the title and links to the twitter page

I needed to get the heading from the original <h2>, to a smaller <h4> body structure on my right column with K2. I also needed to declare a new DIV for each section of the sidebar, Twitter being a major section. After adding the plug-in into my dynamic sidebar within K2, it was displaying however, was showing an in-line bullet point <li> item as noted above. In order to take this out, I needed to remove the <li> reference within mytwitter.php on line 171:

Line 171
?> <li id="mytwitter_widget" class="widget widget_mytwitter"><? mytwitter();?></li><?php
And change it to this:
?> <? mytwitter();?><?php

This removed my <li> element to work with my current theme. Typically I do not alter a plug-in like this however, there are times when as a developer, you must modify core files in order for everything to keep pace with your original style. It is always good to remember the changes you have made, and to keep an original just in case your screwed something up. Its also good to keep a backup of your modifications ESPECIALLY with WordPress 2.5 since it has the new auto update functionality for plug-ins. Which reminds me, time to back those files up!

1 Comments For This Post

  1. Steve

    As I am sure you can tell, Twitter is no longer in use here, nor is the K2 platform however, this material can still be applied to those running the K2 platform under WordPress.

Leave a Reply