Category Archives: Blog

PHP Code Snippet

Because of the re-design, there’s a lot of broken links – mainly because the blog used to live under the /whatithink/ folder on the server and now resides in the root folder. So all those Google links now point to a part of the site that no longer exists.

So anyone coming here from Google is going to get a 404 error. Not good.

While I get my head around using .htaccess to automatically rewrite the broken URLs, I’ve created a 404 page that will, (hopefully), correct the URL.

Here’s the PHP:

$requested = $_SERVER['REQUEST_URI'];$parts = explode('/', $requested);foreach ($parts as $part) {switch($part) {case ('whatithink'):break;case (''):break;default:$out .= '/' . $part;}}$out = 'http://' . $_SERVER['HTTP_HOST'] . $out;

Because all my broken URLs have an extra “/whatithink/” section, I can just break the requested URL into parts, and rebuild it without that section.

Plugin Review – Add Twitter RSS

It’s proving to be a great week for my plugin’s. Following on from WordCast PodCast mentioning WP Frame Breaker, Weblog Tools Collection have just posted a review of another one of my plugins – Add Twitter RSS.

If you use Add Twitter RSS, head on over and let them know what you think.

Add as always, feedback and requests for more options are always welcome.

Top 20 Irish Blogs By Traffic

Being that it’s the first day of 2009, it’s common to do some sort of review: what was good, bad, popular and unpopular about the year that’s just past.

I couldn’t be bothered.1

Instead, I decided to do a “snapshot” post – one of those posts that looks at something current, so that in twelve months time I can look back, do it all again and say “Look what’s changed in the last twelve months”.

After my previous post about the most popular social networking sites in Ireland, I decided to have a look at the most popular Irish Blogs. Before I go through the list, here’s a couple of things to remember:

  • I checked the rankings for 179 blogs. This is by no means an exhaustive list of Irish blogs, so if your one isn’t on the list, email me and I’ll update it.
  • The list of blogs was taken from my own feed reader and from the Blogrolls of a couple of the more popular blogs on this list.
  • The traffic data is taken from Alexa, so while it may not be entirely accurate, it should give a general indication of the relative popularity of those on the list.
  • The traffic is based on the last three months only.
  • The traffic stats do not contain any information regarding email or RSS subscribers.
  • Due to the way that Alexa gathers traffic stats, I was unable to gather stats for blogs hosted on the following sites:,,,

So with all of that out of the way, lets move on to the list:

Number 20 – John Breslin

John Breslin

John Breslin

Number 19 – Bernard Goldbach

Bernard Goldbach

Bernard Goldbach

Number 18 – Cybercom



Number 17 – John M. Ryan

John M. Ryan

John M. Ryan

Number 16 – Twenty Major

Twenty Major

Twenty Major

Number 15 – Grannymar



Number 14 – K8 The G8

K8 The G8

K8 The G8

Number 13 – Limerick Blogger

Limerick Blogger

Limerick Blogger

Number 12 – Jason Roe

Jason Roe

Jason Roe

Number 11 – Whois Ireland

Whois Ireland

Whois Ireland

Number 10 – Cormac Moylan

Cormac Moylan

Cormac Moylan

Number 9 – Frank Prendergast

Frank Prendergast

Frank Prendergast

Number 8 – Sabrina Dent

Sabrina Dent

Sabrina Dent

Number 7 – Bock The Robber

Bock The Robber

Bock The Robber

Number 6 – Head Rambles

Head Rambles

Head Rambles

Number 5 – Tom Raftery

Tom Raftery's I.T. Views

Tom Raftery's I.T. Views

Number 4 – Michele Neylon

Michele Neylon

Michele Neylon

Number 3 – Donncha O’Caoimh

Donncha O'Caoimh

Donncha O'Caoimh

Number 2 – Redfly Marketing

Red Fly Marketing

Red Fly Marketing

In at number one, drum roll please….

Number 1 – Damian Mulley

Damian Mulley

Damian Mulley

In the interests of transparency, you can download the full list of blogs that I checked here. The file is a standard .csv.

  1. Mainly because my memory is so bad, I can’t remember what was good or bad about last week, never-mind the last twelve months. []

Theme Development

I’m currently working a simple black and white theme for this blog. While I’m working out the kinks, you may see some minor changes. Don’t fret, it will be finished soon enough!

WordPress and Page Templates

I’ve been doing a lot of work recently on my employers website. I had been using Joomla as a content management system, but it was overkill for what I wanted, and I found that it wasn’t the most stable of platforms. (Frequently, and for no apparent reason, pages that were published would suddenly become unpublished.) It was more hassle than it was worth, so I got rid of it and installed WordPress instead.

I decided on WordPress as I’m familiar with it, and with a couple of tweaks to the settings it no longer resembled a blog. It was relatively easy to design a simple template, and get the site up and running, but I did have one major issue. I needed an Events page and a News page to display what would traditionally be considered blog postings . The idea was that each page would be linked to one specific category and one category only. In other words, posts in the Events category would only appear on the Events page and posts in the News category would only appear on the News page.

While WordPress does allow you to specify a static page as your “Front Page” and another page as a “Posts Page”, there doesn’t seem to be an easy way to force WordPress to use two Post Pages, or to restrict a Post Page to just one category. One idea I played around with was to edit the header.php file and manually add the links to the actual categories. WordPress would then display the resulting page using archives.php. It’s then a simple enough matter to edit the file to display the posts as needed. It’s a quick solution but it does pose two problems:

  • The links are hard-coded into the header.php file. If for some reason the links are changed, or if the theme is updated, then the links have to be manually changed again.
  • Using links in this manner doesn’t give the same flexibility as allowing WordPress to manage the navigation, Pages and Posts.

The answer I found was to use Page Templates. By putting the code to retrieve the posts from each category into a Page Template I was able to bypass hard-coding the links and I could display only the category I needed on each page. If your interested, you’ll find a sample Page Template here.

My next thought is to expand this into a plugin in order to make easier to select which category should be displayed, and which page it should be linked to. I’ll have to think about how to go about it some more though.

Setting Up Movable Type 4 on a MAMP Server

Recently my hosting provider, Blacknight Solutions, requested that bloggers using WordPress use the WP-Cache plugin to reduce the load on their servers. Michele at Blacknight has been somewhat critical of WordPress in the past, mainly due to it’s inefficient SQL and the resultant high number of database queries required to generate even a simple page. Based on this Michele moved over to Movable Type 4, and despite a few teething problems, he seems to be quiet happy with it.

As part of their control panel, Blacknight provide the handy Installatron Script Installer, however, there is no installer available for MT, so users have to manually install it themselves. Unfortunately my upload connection is so bad, that it me takes hours to upload the approximately 20 MB of MT install files. As I use MAMP for local site development, I’d thought I’d have a go at a local install of MT.

Because of where MAMP is installed, it’s not a straightforward process, there are a couple of “gotchas” along the way. So for those of you interested in performing a local install of MT4, here’s a quick HOWTO.

Before you start, you’ll obviously need MAMP Server, and MT4. You can grab MAMP here, and MT4 here.

Part I: Getting Ready To Install Movable Type

  1. Once you have downloaded the MT4 ZIP file, extract the files to a folder of your choice.
  2. Within this folder, you should now have an MTOS-4.1-en folder.
  3. Open this folder and locate the mt-static folder.
  4. Move the mt-static folder to /Applications/MAMP/htdocs/
  5. Open a new Finder window and browse to /Applications/MAMP/cgi-bin/
  6. Create a new folder, and name it mt
  7. Move the remaining files in the MTOS-4.1-en folder to /Applications/MAMP/cgi-bin/mt/

Part II: Create a SQLite Database

Before starting the Movable Type installer, you need to create a database in which to store your blog settings, posts etc. While the MT developers recommend that you use MySQL for your database, an additional Perl Module is required otherwise MT will not recognise your MySQL server. However, as this will be a local install, SQLite should be more than enough for your needs. (If you really need it, the required module is DBD::mysql which can be found here, but be warned installing it is problematic and time consuming).

  1. Start the MAMP application and click the “Open Start Page” button, or alternatively, type http://localhost:8888/MAMP/ into your address bar.
  2. Click the link for the SQLiteManager at the top of the page.
  3. Type in the name of your database, and select Version 3.
  4. The full path to the database file also needs to be provided. In this example, I’ve called my database mt4, but you’re free to call it whatever you wish.
  5. Note that the path to your database will be /Applications/MAMP/db/sqlite/[your database name].db
  6. Click the Save button, and your database will be created.

Part III: Installing Movable Type

Now that you have all the MT4 files in place, and your database has been created, you’re ready to start the Movable Type web-based installer.

  1. Open your browser, and type in the following address: http://localhost:8888/cgi-bin/mt/mt.cgi
  2. The installer will tell you that the mt-static has either been renamed or moved and will request both the Static Web Path and Static File Path to the folder. Enter the following paths:
    • http://localhost:8888/mt-static
    • /Applications/MAMP/htdocs/mt-static
  3. Click the Begin button and the installer will confirm that the paths you have entered are correct.
  4. The next step brings us to the database connection setup page. Here is where we’ll tell Movable Type where our database is and how to connect to it.
  5. You’ll note that the only database connection available to us is the SQLite Database and once again we’re being asked for the path to the database. This is the exact same path that you entered in Step 6 of Part II above:
  6. In order to proceed, you’ll need to Test the Connection.
  7. Once MT can talk to your database, then Continue onto the next step -setting up your email.
  8. From the drop-down, select Sendmail and accept the default Sendmail path. Enter your email address and click the Send Test Email Button.
  9. The next step is to set up the admin user and password.
  10. The final step is to create your first blog!

More .htaccess Magic

Whilst researching ways to block trackback spam, I had a look at using .htaccess to deny access to the trackback URL for each post. Just in case you’re interested, here’s how it’s done. Add the following lines to the top of the .htaccess file in your blog directory.


SetEnvIfNoCase Request_URI "./trackback/" not_allowed


<Limit GET POST>Deny from env=not_allowed<Limit>

Using .htaccess to Block Spam Bots

Following on from my attempts to block trackback spam, here’s another way to block those pesky spam bots. This only works if your server uses Apache.

Because this only works on Apache, you may have already guessed that it uses the .htaccess file to prevent the spam bot from reaching your page. In order to block a spam bot, you’ll need to know the User Agent for the bot. The User Agent can be found from your web stats package. If you’re using WordPress, then you can use any of the available stats packages to find the user agents hitting your site. (I use FireStats and StatPress.)

Before you edit your .htaccess a word of warning:


Be very sure of what you’re doing.


Because .htaccess controls access to your website, you could find yourself locked out of your own website. If that happens, you’ll need to contact your hosting provider and ask them to make the changes for you.

Once you’re ready to edit your .htaccess file, open your preferred text editor and save a blank file as htaccess. Notice that there is no dot in front of the name. The reason for this is that most modern OSes will hide any file with a filename starting with a dot, and you’ll need to be able to find the file later on.

At the top of your new htaccess file type the following:

SetEnvIfNoCase User-Agent "^User Agent To Be Blocked" bad_bot

If you want to block more than one User Agent, then add the above line for each spam bot to be blocked.

Under this, you’ll need to add the following lines:

<Limit GET POST>Order Allow,DenyAllow from allDeny from env=bad_bot</Limit>

Save the changes you’ve just made, and fire up your preferred FTP program. Upload the file to the root directory of your website or blog using the ASCII file type. Once the file has been upload, use your FTP program to rename the file to .htaccess.

Check your website to ensure that you can access it, and you’re good to go!

Changing How WordPress Displays the Date and Time

If you’ve had a blog for any length of time you’ll be hard pressed not to play around with it and mould it to your own needs. Even if you find a theme that you like, there will always be the odd thing that you want to change.

In my case, I wanted to change how the date and time were displayed on my blog posts – it was just a bit too “American” for my tastes. WordPress allows you to change the default date and time formats, (it’s under Options), but changing this had no effect. Obviously, the time and date formats were hard-coded into the theme files.

So I fired up my FTP program and downloaded copies of archive.php (displays the archive pages), single.php (displays a single post per page – basically the permalink page), and index.php (displays the main home page).

WordPress uses a specific function for displaying the date and time. So it was just a matter of searching each file for:

<?php the_time('F j, Y '); ?>

This displays the date as:

December 14, 2007

I changed the code to the following:

<?php the_time('l, jS F, Y'); ?>

which displays the date as follows:

Friday, 14th December, 2007

If you need a description of what the different parameters mean, then you can find more information from the WordPress Documentation Site and from the PHP Manual.

Using WordPress Pages to Link to Another Site

You may have noticed that since I changed the theme for this site that there is now a page called “” that directly links back to the root of my website. Unlike a normal WordPress page, this page links to a document completely outside the WordPress hierarchy.

I’m sure that it would be possible to hard-code the link into the theme files, but every time the theme is changed, the changes would have to be re-coded again. There’s also the fact that every theme is slightly different, so each theme change could mean starting from scratch. Instead it’s much easier to update the WordPress database.

Updating the database will ensure that the changes are persistent across theme changes. The downside is that if you’re not careful, you could hose your entire WordPress installation. So if you’re going to do this, make a backup. I’ll say that again – backup your WordPress database before you even think of doing this.

The first step is to create a standard WordPress page. The title of the page should be the name that you want to appear in the link. In my case the page title was “”. Under the discussion tab on the right hand side of the writing pane, untick the “Allow Comments” and “Allow Pings” options. Don’t enter any content and publish the page.

Now it’s time to edit the WordPress database. To do this you’ll need access to phpMyAdmin. Connect to your WordPress database and look for the wp_posts table. Choose the option to browse this table. You now need to locate the entry that corresponds to the page you’ve just created. It should be the last entry in the table.

Now that you have located the page entry, it’s time to edit the database. Click the edit icon. There are two items that you need to change. The first is “post_name”. This should be changed to reflect the URL that you want to link to. If you want to link to a page that is in the root of your website, you need to use relative addressing. For example, in my case, I changed the “post_item” to “../index.php”.

The second item that needs to be changed is the “guid”. This should be changed to the full address that you’re linking to, including the “http://www”.

To apply the changes that you’ve just made, click the Go button. Exit out of phpMyAdmin and you’re ready to test your changes. Refresh your blog and test that the link takes you where you want to go.

Update: Changed the name of database entry from “post_item” to “post_name”.