Main

29th April, 2004

WordPress Hacks

Filed under: WordPress, — bsag @ 07:05 PM

I’ve just upgraded to WordPress 1.2 beta—-a wonderfully easy and trouble-free process. I think it speaks volumes for the quality of the coding in WordPress that I’ve been using an alpha version since I switched, without any significant problems. The beta has been tidied up a great deal, and if you currently have 1.0.x installed, you’ll find a lot of nice new features. For me, the big improvements are the customisable meta-data you can attach to each post (this is how the EXIF data is stored in Pictorialis, which I use for my photoblog), and the Plugin architecture. You used to have to manually paste the code for hacks into a my-hacks.php file. It wasn’t particularly difficult, but perhaps a bit off-putting for beginners. Now the same functionality can be provided by plugins which are just dropped into a directory. They then appear on the Plugins page of the admin interface, where you can enable and disable them with a single click.

I promised—-when I wrote about my reasons for switching—-that I would list the hacks I had used on my site. Now seems as good a time as any to do that.

The main structure of the site is very similar to the default install. I set up index.php how I wanted it, then put the repeated sections (the header, sidebar, and footer) into separate files to include as follows: include_once('header.php');. I also put an if statement within the loop that iterates over the posts to check whether the variable $p is set. On the individual post pages, this variable holds the post id, so if it isn’t empty, we’re on an individual page:

if ($p!="") { include_once('crumbs.php'); }

The crumbs.php file holds the code for the previous/next post links, which appear at the top of the individual post pages.

Once I had got the index page the way I wanted it, I ‘hollowed it out’ by removing all the code to handle the post and comment loops, and then used that as a template to build a few of the static pages, like the ‘about’ page. I used a similar process with the archive page, which uses nice drop-down menus to allow you to view the archive by date, title or category, and filter by year. I’m struggling to remember where I got the file that formed the basis of the archive code, but I think it might have been from WuhWuh. I made a few adaptations to make it work with the human and search engine friendly permalinks.

The remaining customisations are mainly hacks that I have used as provided, or modified slightly to make them work as plugins.

  • Amazon Media Manager: This great hack sets up an admin page for adding books, CDs or DVDs via Amazon’s listing. All you need to do is enter the ISBN number of a book, or the Amazon ASIN number for other media. It then collects the details of the item, including the cover image. All you need to do then is include a simple piece of code on your page where you want to list your items. It’s very easy to customise, so you can show a random item, the last x items, or restrict it to one kind of medium. As an added bonus, if you add your Amazon Associate ID to the configuration file, it will automatically generate the links to Amazon appropriately to include your ID. I used to do all this manually, and it was a real hassle.
  • MagpieRSS: This is excellent—-it allows you to suck down any RSS feed and display it in a very flexible way on your page. If you actually read the instructions properly (unlike me!) it takes care of caching the feeds so that you don’t hammer the server providing the feed.
  • most-popular: This provides a template function to allow you to list the most-visited posts. You can see this in action on the sidebar.
  • Recent Comments: Lists the last x comments.
  • Search Hilite: This is included in WordPress 1.2. If visitors reach your page as a result of a Google search, this hack highlights the search terms on your page in yellow (or whatever colour you choose). Try it!
  • Live Comment Preview: This powers the ‘as-you-type’ preview when you type in the comments box.
  • wp_backup: An essential hack to allow one-click backup and restoration of the database.
  • wpblacklist: Another really handy hack to scan incoming comments for spam words, and automatically put them in a comment moderation queue, so that they don’t appear on the page until you approve them.

I think that’s about it for now, but no doubt I’ll be adding a lot more as time goes on.

Update: I forgot another vital part of my switching process, because it isn’t a part of WordPress per se, but a nonetheless essential tool. It’s mt-wp-redirect by Alex King, which automates the process of permanently redirecting your old blog entries to your new ones. It’s very easy to use.

blog comments powered by Disqus

Powered by ExpressionEngine :: © www.rousette.org.uk, 2002-2008 :: [XHTML] [CSS] [508]