Archive for WordPress

Fixing the Tab Index with Brian’s Threaded Comments

A lot of blogs are starting to make use of a cool Wordpress plugin called Brian’s Threaded Comments.

This plugin, once enabled, turns your comments into a threaded structure to make it easer for readers to reply to a specific comment.

This is a great plugin, but it isn’t without flaws. There seems to be some sort of JavaScript error in Internet Explorer when I use this plugin with my template, so I’ve disabled it for now.

I have, however, found a fix for the tab index flaw that’s been plaguing me when replying to comments on blogs that use this plugin.

Fixing this problem is fairly simple: add tabindex="5" to the Add Comment button in your template’s comments.php file (the name parameter for the Add Comment button is addcommentbutton in case you’ve changed the text of the button itself).

By adding this tabindex value to the Add Comment button the focus moves to the button when you press the tab key while the comment text area has focus.

Once you’ve added this fix the top of the page will no longer annoyingly gain focus when pressing the tab key while the comment text area has focus. This makes the process of typing and posting a comment much easier for your readers.

Do your readers [me] a favor and implement this tabindex value. They [I] will love you for it.

Tags: , ,

Building SAJAX Applications with Wordpress

The Simple AJAX Toolkit, or SAJAX for short, is a library you can use to quickly build AJAX applications in PHP, Perl, ASP, and many other languages.

Using SAJAX with Wordpress can be tricky, because if you don’t initialize SAJAX or handle client requests at the correct time you’ll break Wordpress, your SAJAX applications, or both, and this guide will help keep you from doing both.

If you haven’t done so already, you should strongly consider integrating a custom PHP library into Wordpress. This isn’t a prerequisite, but it allows you to easily integrate your own SAJAX functions into Wordpress.

Integrating SAJAX Initialization into Wordpress

To use SAJAX with Wordpress without a custom PHP library you’ll need to edit wp-config.php, but to use SAJAX with Wordpress with a custom PHP library you’ll need to edit lib/LIB.php.

The instructions below apply to both variations, but if you’re editing wp-config.php make sure you place your SAJAX code right before the ending ?> line.

  1. Include the SAJAX library with include("Sajax.php"); and initialize the SAJAX library with sajax_init();
  2. After initializing SAJAX you’ll want to include your SAJAX functions with the appropriate sajax_export() declarations.
  3. Once you’ve exported all of your SAJAX functions add sajax_handle_client_request(); to handle all SAJAX requests before they’re passed to Wordpress. If Wordpress tries to handle the request it’ll have no idea what to do and your SAJAX application won’t work!

Once you’ve got SAJAX integrated into Wordpress you’ll need to edit your template so that you can use the JavaScript SAJAX provides.

To do this you’ll need to add the following code to the template file(s) you wish to use SAJAX in:

<script type="text/javascript">
<?php sajax_show_javascript(); ?>
</script>

If you want to use SAJAX in every page of your site then consider placing this in header.php.

Using the steps above you can now start calling the SAJAX JavaScript functions to dynamically interact with your web server and update the page’s content.

More Information

For more information about SAJAX visit the official SAJAX website where the SAJAX FAQ should get you started.

If you’re building web applications you now have no reason to miss out on the interactivity AJAX provides you, as SAJAX and Wordpress make building AJAX applications a snap.

Tags: , , ,

Integrating a Custom PHP Library into Wordpress

Ever since starting my first Wordpress blog in December 2005 I’ve come to appreciate what Wordpress brings to the table right out of the box.

From then to now I’ve started using Wordpress with websites where blogging is simply an added benefit; the main focus of the websites is something other than a blog.

As a one man show, Wordpress can be invaluable for creating websites that aren’t blog-centric.

You could always create your own repository of reusable website code and templates, but Wordpress gives you so much more: a broad user base that finds and quickly patches bugs, useful 3rd party plugins that you don’t have to develop yourself, and a plethora of themes that you can use to help get your website running (especially if you’re not a color guy like myself).

There is, however, one component you’ll need to build yourself when you want to use Wordpress for a website with dynamic content: a custom PHP library.

Integrating Your Own PHP Library into Wordpress

Integrating a custom PHP library into Wordpress can be done in three simple steps:

  1. Create a lib directory in the Wordpress root directory.
  2. Create a PHP script called LIB.php in the lib directory created in the first step.
  3. Modify wp-config.php and add the line include(”lib/LIB.php”); at the end of the file (before the ending ?> line).

The custom PHP library is now integrated into Wordpress, and you can now start building your custom PHP scripts and include them in the lib/LIB.php file.

Once you’ve built your library of functions you can add them into your Wordpress templates so that they show up on your site.

Other Reasons for Creating a Custom PHP Library

Other than managing dynamic data, you’ll also want to create a custom PHP library if you want to override any default Wordpress functions.

For example: one site I have overrides the get_the_title() and the_permalink() functions to do as I please.

Note that you’ll need to make sure you comment out the existing functions inside of the appropriate files located in the wp-includes directory.

Why Not Build a Plugin Instead?

Wordpress has a feature rich plugin interface, but if you’ve already got a custom PHP library then it’s much easier to integrate it into Wordpress using the methodology above.

Also, if you want to use your custom PHP library with more than just Wordpress (for performing background data parsing, for example) then using this method will give you the ability to perform this type of functionality with ease.

The only drawback to using this method is that you can’t easily attach menus to the Wordpress Site Admin interface as far as I can tell (although I’ve never tried), but I don’t have a need for this functionality, so it’s not a big deal for me (and hopefully not you, too).

Hopefully you find this guide useful when building your next Wordpress based website that’s more than just a plain old blog.

Tags: , , ,

Why You Should Embrace Top Commentator Whores

If you’re having a hard time deciding whether you should follow the recent trend of adding the Show Top Commentators plugin to your Wordpress blog then I’m going to make the decision easy for you.

To do this you’ll just have to ask yourself one question: “Does my blog’s target market run their own website?” If you answer yes to this question then you should be using the show top commentators plugin.

I was first introduced to this plugin over at John Chow’s blog in his late-December Two Plugins To Increase Blog Comments post, and I was initially skeptical of this plugin. My first reaction was that this plugin would be a spammer’s dream come true.

Now, however, I’ve come to the realization that you should embrace top commentator whores. John was right in that the plugin is a good way of increasing community interaction, but there’s another subtle benefit that will mean much more to the long term growth of your blog: The show top commentators plugin will turn casual readers into sneezing fanatics.

If you have a truly remarkable blog with top quality content then you’re losing out by not using this plugin. By turning the casual reader into an everyday reader at the cost of 5 to 10 (or however many are appropriate) linkbacks you’re going to obtain and maintain more readers than you would otherwise.

As you can imagine these top commentator whores already have a website, so they’re more likely than the normal reader to link to your blog. In this current day and age of Google PageRank and Technorati Rankings these types of readers are invaluable to your blog, as they’re likely to attract more readers to your blog that are just like them.

But what do I do about spam?

By using this plugin you’re guaranteed to get some amount of spam, and there are a few things you can do about it. First, the plugin provides a configuration option that allows you to filter out users and/or URLs from showing up in the top commentators. If you find someone routinely abusing your plugin for a site related to content you don’t agree with then just add them to the filter.

You can also mark all of their comments as spam and hope Akismet catches on, and you can also use the various filtering options Wordpress provides to help limit spam. Spam will come to your posts regardless, so the benefits of using this plugin far outweigh the possible spam.

I am a Top Commentator Whore

I want to thank a few blogs in which I have top commentator whore status that helped me come to realize why you should embrace top commentator whores: John Chow dot Com, JohnTP.com, HMTK.com, King Nomar dot Com, and Alex Blogging.

These aren’t the only blogs I’ve whored my comments out to, but without the top commentator plugin I might not have ever visited these blogs (or stayed for very long). Now, however, I visit these blogs for more than whoring comments: I visit for the unique and quality (or in some cases entertaining) content they provide that I would have missed out on if it weren’t for the top commentators plugin.

I just started this blog this week, so comment on this post to be one of the first people to join my community of top commentator whores. What do you have to lose? You already know I’ll love all of my top commentator whores!

Download the Show Top Commentators plugin now.

Tags: , , ,

Fixing JavaScript Affiliate Links in Wordpress 2.1.1

Wordpress 2.1.1 was released yesterday so I took the time to upgrade my blogs to this latest version. Some of my sites were running 2.0.7, so I figured now was a good a time as any to get to the 2.1 release.

All was good, however, until I found out that any links created by JavaScript that were embedded inside of Wordpress posts or pages were creating a nasty spacing issue.

At some point between Wordpress 2.0.7 and 2.1.1 the developers decided it was a good idea to add the SCRIPT tag as an element that should get some extra spacing to make sure it looks good.

I’m fine with that, I guess, but there’s one major problem I have with this: some Commission Junction (CJ.com) affiliates require that links be JavaScript instead of normal A tags. As such, when you try to use these links in the flow of a Wordpress post or page with Wordpress 2.1.1 you get undesired spacing above and below the link.

As you can imagine this doesn’t flow well inside of the post or page, but thankfully there’s an easy way to fix the problem.

To fix this problem you’ll need to edit wp-includes/formatting.php. Go to line 59 and remove ‘|script’ from the $allblocks variable. Each of the items in this variable is delimited by a ‘|’ (pipe), so make sure you remove one of those along with the word ’script’.

Thankfully this is an easy thing to fix, but it’ll be a change you’ll have to do whenever you upgrade Wordpress in the future.

Tags: , , , , , , ,