29 Apr 2004

WordPress Hacks

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.

  1. 1

    I'm thinking more and more that WordPress is the way I'm going to go for the revamp of d4d™. Many thanks for the info smile----- very cool. thanks for the info. I'm working on moving to a new site that uses WordPress, and this is most helpful!

    by bob @ 30/04/2004 4:05 pm • Permalink

  • 2

    Lyle: Go for it! I've found it a very positive experience. bob: No problem.

    by bsag @ 30/04/2004 6:04 pm • Permalink

  • 3

    Heh, I've just noticed that two things broke in the new version, both apparently as a consequence of $p not being set with the post id any more: the navigation crumbs don't appear on the individual pages, and the Most popular posts thing isn't updating. I'm working on a way around it...

    by bsag @ 30/04/2004 7:05 pm • Permalink

  • 4

    I was going to mention the Alex King site, but it looks like you already got it in your update. I've never used WordPress before (being a big fan of Blosxom myself, though possibly looking for a change--again), but he has a small selection of hacks. I can't tell how good they are, but knowing his work (I use his "Tasks" on a regular basis) I'd imagine that they were top-notch. He also recently hosted a contest for WordPress themes; he has links to them on his site. There are many excellent and incredible themes there for this using. Don't get me wrong, I love your theme Bsag--I'm just pointing out a great resource for other folks who may be interested in WordPress (such as myself...)

    by Nathan @ 30/04/2004 11:05 pm • Permalink

  • 5

    Nathan: That's a very good point. His hacks are great, and the style sheets produced in his competition (and the style switcher you can also use to switch between then) are wonderful. I use Tasks too, and host it on my own computer now that I've got Apache and PHP working.

    by bsag @ 01/05/2004 6:06 pm • Permalink

  • 6

    I've just moved from Blogger to WordPress and am delighted at how quickly and easily the install went (would have been easier if I'd set it up in a sensible folder in my webspace so I wouldn't have to copy image files all over the place, of course). I've not installed any of the hacks yet (just been tweaking the CSS based on a couple of the competition entries at Alex King's site to suit me) but I've no real reason to doubt they'll be very useful in time. Compared to blogger it's just a joy to work with such a flexible tool. Ah, bliss.

    by Em² @ 02/05/2004 11:05 pm • Permalink

  • 7

    I've tried upgrading and got into no end of trouble so I just reinstalled the set-up I had in palce. I also tried to get the Back-Up/Restore hack working but I get a permissions denied message. I guess I need to do a bit more thinking! Having started playing with WP I am dreadfully impressed with all the hacks you've got working.You're clearly a WP wizz!

    by jb @ 05/05/2004 4:06 pm • Permalink

  • 8

    jb: I'm sorry to hear that. Apart from a couple of minor problems, it was fairly smooth for me. The key thing is to remember not to overwrite your index.php and wp-layout.php if you've spent ages customising them. grin Send me an email if you like about the Backup hack, and I'll see what I can do.

    by bsag @ 05/05/2004 6:06 pm • Permalink

  • 9

    Is your crumbs.php a sourced plug in or did you write it yourself? It's one of the few criticisms of the system I have (that and the error pages!) but apart from that I really like it. Still running 1.0.2 at the moment but will play with the beta of 1.2 at your recommendation!

    by Dragon @ 14/05/2004 3:05 pm • Permalink

  • 10

    It is decided Okay, I found what I was looking for with Wordpress. Once I did some digging, I am very impressed with what Wordpress can do. I will be doing the new project in Wordpress, and if I'm feeling fiesty, may move... -----

    by joe mullins dot com @ 21/05/2004 5:05 am • Permalink

  • 11

    Wordpress takes the prize from where I stand, we are also playing around with MU - the multi user platform. awesome.

    by Dubai @ 26/02/2008 10:34 am • Permalink