WordPress

WordPress Logo

Logging Errors In WordPress

21st June 2011 - 3 minutes read time

To debug WordPress many sites will tell you to add the WP_DEBUG setting on its own to your wp-config.php file, but this can be quite harmful as many server configurations will start showing PHP errors and warning messages on your site pages. Most sites will also log any errors to some form or error log, but this isn't always the best place for them to go.

It is possible to add a set of debug options that will allow WordPress to log any errors or warnings to a file. Open up your wp-config.php file and add the following lines of code above the line that says "/* That's all, stop editing! Happy blogging. */". Any changes to this file should always go above this line so that you can keep track of them.

WordPress Logo

The Correct Way To Load A Template File In WordPress

18th December 2010 - 4 minutes read time

Since WordPress 3.0 there has been a funcion called get_template_part(), which has been used quite a bit in the new Twenty Ten default WordPress theme. This is an evolution of the usual way to include parts of themes by using functions like get_header() to include the header.php file. This function helps code resuse by including the same files multiple files, but also allows child themes to override parent themes.

The function takes a required slug and an optional name as parameters, the two parameters being used together to select the correct template file to include. The best way to describe how this function works is to show how it would work in certain situations. Take the following call to get_template_part() using only the slug parameter.

WordPress Logo

Extending The WordPress Page Walker

1st November 2010 - 8 minutes read time

I have looked at printing an intelligent list of WordPress pages in a previous blog post, but I wanted to revisit this topic and use the Walker classes that are part of WordPress. The Walker class is an abstract class that sorts out a lot of the basic functionality needed to extract and render a hierarchical list of items from a database. It is essentially an iterator class that understands lists of items that contain lists of items and can be used anywhere in WordPress where this structure is needed. The Walker class can be found in the file wp-includes/classes.php along with four other classes that extend Walker, these are.

WordPress Logo

WordCampUK 2010: A Review

21st July 2010 - 27 minutes read time

WordCampUK is an informal 2 day conference and barcamp that centers around using, working with and developing in WordPress. This year's WordCampUK was held in Manchester and so being local I could hardly miss the opportunity to attend. It was a great event, with great talks and lots of friendly people who were really enthusiastic about WordPress.

WordPress Logo

Custom Post Types In WordPress 3.0

12th July 2010 - 32 minutes read time

This article relates to WordPress 3.0. Much of the code posted here won't work on previous versions and some of the information may change in newer versions.

WordPress already comes with five different content types built into the system.

Posts

This is the standard content type and is generally the most used in a blog install. Posts tend to be aggregated onto pages but this is not always the case.

Pages

This is a static content type and is used to display non-aggregated pages.

Attachments

Every time you upload a file through WordPress it will store a record of it in this area. You can see this list of files by going to the Media menu item in your admin area. This is what is used when you click on the Media Libray tab on the Add and Image dialog in the edit post screen.

Revisions

WordPress Logo

Wordpress Category Post List

24th June 2010 - 3 minutes read time

A friend of mine asked me to write a Wordpress function the other day that printed out a list of categories and any posts in those categories, along with any meta data that might be in the post.

All the function does is to get a list of categories and then for each category get a list of the posts associated with that category. Not much really, but useful in some circumstances.

WordPress Logo

Wordpress 3.0 Released!

18th June 2010 - 2 minutes read time

It's been a while in the making but yesterday saw the release of the latest major version of Wordpress. I had a feeling it would be pretty soon as there as the final release candidate (RC3) was released last week. You can the Wordpress 3.0 download page below:

Download Wordpress 3.0

WordPress Logo

Wordpress Dynamic Page Menu Navigation

19th May 2010 - 8 minutes read time

After writing the function that creates a list of pages that are children of a given page in Wordpress I needed something more robust and automatic. To that end I created a plugin that will create a widget that contains a dynamically created menu of pages.

The widget figures out what page is currently being displayed and will climb the page tree until it finds the root page. Whilst climbing the page tree the plugin will keep the path to the currently selected page and when the tree is printed out the path will be open. It is best suited for sites that have a solid hieratic page structure, rather than a simple blogging site.

In terms of efficiency I have tested it with pages nested up to 25 levels deep with only a small decrease in page load. However, for the average small Wordpress site this plugin is perfect as pages will only be nested a few levels deep.

WordPress Logo

Add Enctype To Wordpress Post And Page Forms

27th March 2010 - 2 minutes read time

Whilst creating a small plugin on a Wordpress site I decided not to use the media library as I just wanted to add some small stub images to the content. I created some boxes on the post page using add_meta_box() and added a file input box to them. The only thing is that the post form in Wordpress doesn't have the enctype="multipart/form-data" attribute and so it won't pass file to the $_FILES array in PHP.

It is not possible to add the enctype into the form declaration via Wordpress as there is no hook or action to do this. So the only alternative (rather than hack the source code) is to add the attribute using JavaScript, and as we have JQuery already loaded we can utilise that.

WordPress Logo

Wordpress Database Changes When Moving Site

27th March 2010 - 5 minutes read time

When moving a Wordpress install from one place to another there are a number of things you must be aware of. If you have created your templates properly you will have used calls to bloginfo('home') rather than using static links, but you will need to update these links to make your Wordpress install work properly.

Once the files are in place, the database connection details have been edited and the database created there are a number of things to alter in the database to make your Wordpress install work.

The most important changes are in the options table. There are two references to your URL in this table that must be altered to stop Wordpress redirecting back to your old site. This must be done via database access as Wordpress will redirect you when you try to login to the stie.