kieranbarnes Independent PHP, WordPress & CubeCart Programmer

Adding .html suffix to WordPress Rewrites

Posted on March 22, 2012

Posted by kieran

Here's a quick way to give your WordPress install a static look.

Add this code to your functions.php

[Snippet] Adding your custom taxonomy to post/page list in WordPress

Posted on March 5, 2012

Posted by kieran

Custom Taxonomies are amazing for organising your post data. Here's a simple way of showing your custom taxonomies on the post/page list in wp-admin.

In the image below you can see we are now showing the custom taxo Brand in the post list.

 

Here's how I did it

Automatic Photo Blogging with WordPress

Posted on March 5, 2012

Posted by kieran

My latest WordPress challenge was to automate a photo blog site. The photo blog post content would just consist of a title and a featured image. No content. As per normal photo blog style sites.

This solution takes an image at random from a folder and posts it in WordPress. It relies on a healthy collection of images to work from.

Really simply, it needed to select a photo at random and post it. Sounds easy, until to you start to code it.

Here's my solution.

Server Side PNG Optimisation with TimThumb

Posted on March 4, 2012

Posted by kieran

A little known feature of TimThumb is that is supports server side PNG optimisation.

Using the OptiPNG program (Available for Linux and Windows) TimThumb can losslessly compress PNGs on the fly.

Quick tests showed an original clients PNG came in at  671Kb, OptiPNG compressed that with no visible difference to 580Kb and nominal server load.

So lets go ahead and use it.

Tagged as: , Continue reading

Removing all comment functionality in WordPress

Posted on February 27, 2012

Posted by kieran

As more and more people adopt WordPress as a CMS, more and more of the original blog functionality is becoming redundant. Comments are one of.

Here is how to conclusively remove all comment functions in WordPress

Caching TimThumb images in memory

Posted on February 26, 2012

Posted by kieran

TimThumb, properly configured & secured is a very useful tool for image manipulation. Amidst all it's old security flaws, the new version is pretty secure.

Sometimes it can be pretty slow though. By default it only caches images for 24 hours. Probably not long enough if you are just creating static thumbnails of larger images that don't change.

I'd recommend changing it to 31,556,926 seconds - one year.

WordPress Opengraph and Microdata Generation without a plugin

Posted on February 17, 2012

Posted by kieran

Its really useful to have Opengraph (Facebook) and Microdata (Twitter) information in your blog header.

The Facebook Opengraph and Schema.org microdata lets you optimize your blog much more better and helps search engines to index your website better to show rich snippet.

It also lets Facebook and Twitter users to share your blog with proper title, description, url and image.

There are loads of plugins available to do this, but why use a plugin when its only a few lines of code?

[Snippet] Matching hash tags in Twitter content

Posted on February 17, 2012

Posted by kieran

Here's a super simple way of matching hash tag content in a tweet.
Perhaps you want to store hash tags as WordPress tags? Or simply transform how they are displayed?

  1. preg_match_all('/#(\w+)/',$data->text,$hashtag_matches);
  2. print_r($hashtag_matches);

Where $data->text is your tweet string.

Easy.

Tagged as: No Comments

[Snippet] Convert Twitter Date to MySQL Date

Posted on February 16, 2012

Posted by kieran

If you are pulling tweets from Twitter's Firehose streaming API or the search.atom/search.json APIs, you will be getting Twitter's really annoying non-standard date format.

To convert their date format into MySQL's date format for storing in a date column, try this;

  1. date('Y-m-d H:i:s', strtotime($tweet->updated));

Where $tweet->updated is your Twitter date (This example uses the search.atom & SimpleXML).

Or, do you store your dates as Unixtime?

  1. date('U', strtotime($tweet->updated));

You could also use gmdate to return the date & time in GMT. Rule Britannia!

[Snippet] Setting the timezone for PHP 5.3

Posted on January 25, 2012

Posted by kieran

PHP 5.3 requires a time zone to be set if you do any kind of date processing.

Simply set this in your php.ini

  1. // London, England, Europe
  2. date.timezone = "Europe/London"
  3. date.default_latitude = 51.500181
  4. date.default_longitude = -0.12619
Page 1 of 1112345...10...Last »