Recursive Filesearch using the PHP Glob function

Jul 31, 2012

A really simple snippet of code that I tend to use when doing big imports of data into a database system. It is rare that the people preparing the files are perfect at following file naming conventions so being able to allow for a bit of flexibility is vital and this tends to do the job. Performance wise this isn’t great because you do a lot of searching that you probably shouldn’t need to do but that is up to the developer to either work around or just be aware of.

Update: WordPress – Dealing with lots of standard image sizes

Jul 31, 2012

This is an update to the blog post and gist I wrote about getting image source filenames from wordpress when all you have is the thumbnail version. It turns out the whole thing is a bit more complicated, especially if your client/editor is uploading files that already have dimensions in the filenames. Not to mention an odd little WordPress “feature” where you sometimes don’t get the files in the sizes you expect.

PHP Array Delete

Nov 25, 2011

Can PHP really be missing a way of deleting items from an array based on the key? Seems so, so here am am just sharing a snippet of code that lets you do just that. This function will work with any number of array keys and does some clever shunting around with the array_flip and array_slice functions. // utility to remove array items from the key function array_remove_key() { $args = func_get_args(); return array_diff_key($args[0],array_flip(array_slice($args,1))); } // usage...

Lite Website Content Management Options

Aug 15, 2011

Building websites that can be quickly and easily updated is vitally important but with so many content management systems available how do you make the decision as to which one to use. I am really concentrating on what I would categories as “lite” content solutions. Sites that take the pain out of managing your design and content but aren’t going to give you absolutely everything you might ever need in the process.

Display your Magento store address (from the configuration)

Jun 6, 2011

Magento lets you enter your store address directly into the configuration settings – here is the code snippet to display that in one of your Magento Templates. First of all the setting is found in the system-Configuration page under General – Shop Information. Obviously you can vary this for different Store Views etc. Here is a quick screenshot to make sure you are in the right place… Configuration General-Shop->Information” src=“/wp-content/uploads/2011/06/Mageno-System-Configuration-General-Shop-Information-575x212.png” alt=“Magento System->Configuration General-Shop->Information” width=“575” height=“212” /> the code to then display this in one of your templates is then a one line snippet of PHP… echo Mage::getStoreConfig('general/store_information/address'); You probably want to display on multiple lines – by default this will just include line breaks that will then be ignored in HTML.

How to Reorder your Magento Footer Links and A Walkthrough the Magento Layout/Template System

May 25, 2011

I have built a number of Magento sites and have managed to avoid the awkward question of setting the order of the footer links, here I describe how it can be done with some extra explanation into how Magento makes it all happen. First let me explain where the links are in the Magento structure, so you can add, edit or remove them from the footer links. The links are added into the page in the template/page/html/footer.phtml file, where there are two links – usually your template will have one called footer_links and a second one called something like cms_footer_links.

Display Category Descriptions, Tag Descriptions and Author Bio’s in WordPress

May 6, 2011

Most WordPress templates don’t seem to support displaying the descriptions for categories, tags and the author bio’s. Here is a quick explanation of how you add that information into your WordPress admin and then how to change your templates to display it. The main reason for wanting to do this is simply to provide a little extra supplementary information on lots of your blogs pages – but it may also have some benefit for SEO as well.

Get the title of an order’s payment method in Magento

Apr 8, 2011

I have been writing a magento based site for a client and they have a few requirements for their despatch system that I had not seen before. One of them is to set a flag in their dispatch system indicating the payment method chosen by the customer (seems sensible, I just haven’t had to do it before). Anyway, turns out as it often is with Magento, that this is a really simple thing to do, once you find the information.

How to check if a string contains another string in PHP

Apr 7, 2011

This post is another quick explanation on something that is is much more difficult to figure out than it should be. One of the most basic things you would ever want to do in programming is check if one string of text contains another string of text. In every other programming language I can think of this is simple but for some reason the PHP way of doing this has added complexity.

Building a website switcher module for Magento

Mar 25, 2011

I recently had to build a module for Magento that let you switch between each of the Magento Websites in the admin. I’ve written a short explanation of how I did this below, along with the code. Create a module First off, you need a name for your company/organisation and a name for your module. Once you decide that you need to create the folders. You will probably want to put your module on the local scope – this is where I do everything, although if you are developing a plugin then people sometimes use the community scope.