Ramblings of a madman.

Offering WordPress training as a service

I interact with WordPress at least once a day in some form or another. Whether I’m installing a WordPress site for a client, developing themes & plugins or writing a blog post just like this one, I’m always using it.

As of the 23rd of January I’ll also be embarking on a PTTLS course at Gosforth Academy. I’ve given presentations and taught IT practices before at University and when I worked at British Airways and now I’m looking forward to doing the same with WordPress.

As of February I’ll be available to take half day and full day training sessions at your business. This will initially cover Newcastle, Gateshead, Sunderland, Durham, Edinburgh and generally anywhere in the North-East of England & Scotland.

You can read more about my services on my WordPress training page.

Using WordPress over bespoke solutions

There’s a decision a web developer or a web development agency has to make when providing a Content Management System (CMS) to their client. There’s several factors that might sway the decision one way or another. I use WordPress, which I think is an excellent tool for providing CMS driven websites as well as building more complex solutions – here are reasons why I use WordPress and possibly a few misconceptions of why other people don’t.

Time

It’s not the main consideration but time is, of course, a large factor. There’s the initial time to design, build and test the system and additional time to maintain it once you have it running. There’s also the regression testing that needs to be carried out following the addition of extra features. All this time could be spent on designing the client’s website, implementing social media or helping with other aspects of delivery. Alternatively the time could be reduced and therefore the cost could be reduced.

Quality

Automattic (the company who develop WordPress) have experts in key areas such as User Interface (UI), User Experience (UX), Architecture and Security. For bespoke software you would have to have personnel who were good at each of those, plus developers to actually build it. As a freelancer or small business (which most web agencies are) that simply isn’t possible without large overheads. If they’re developing a CMS then the chances are those overheads are going to be passed onto the client, or it’s going to be a secondary thought – which could result in the system becoming quickly out-of-date.

Support

The code base for WordPress is open source (GPL license). This means that anybody is free to take a copy of the code, change it and resell it for a profit. People like myself profit from doing just that, however an altruistic nature in the WordPress community has arisen. This has resulted in the creation of excellent resources and plugins which are in turn, open source. What this also means for businesses is that once they have had their site developed in WordPress then there are lots of people who can support them and they are not tied with one company that will charge them through the roof.

Perception

WordPress has a perception that is it only suitable for blogs. Whereas this was the case two or three years ago, with the introduction of ‘custom post types’ in version 3.0 (2010), this has prompted the community to extend the usage beyond imagination – the fact that WordPress is now even being used for e-commerce* clearly represents that some people’s perceptions about WordPress are out-of-date. Unfortunately clients and agencies still have this perception and by doing so are only restricting their possibilities.

* Although not a replacement for Magento, Shopify etc

Taste

At the end of the day, everyone is entitled to their opinion and they simply might not like WordPress. I personally like the admin area, which is the part of the site where the client will spend most of their time editing their website. I also find the API relatively straightforward to extend WordPress, however some other developers may prefer different a different CMS such as Drupal or Joomla. I can accept that WordPress isn’t for everyone. I can also agree that there are times when it’s maybe best to start with a (relatively) blank slate – my point is don’t just reject it.

Final Thoughts

As a client you should be willing to listen to the option of using WordPress and know that any comments you have heard about it in the past may no longer still be relevant. It’s also very important once your site is live for it to be supportable and it is kept up-to-date otherwise you may end up paying high support costs and be forced to invest in a new website altogether further down the line.

My main advice, however, is just to be open minded and consider all the facts before you make a decision on why WordPress might not be good enough for you; the chances is are it’s probably better than you had anticipated.

 

WordPress Quicktip for WP_Query

If you’ve ever wanted to use the WP_Query class to query the database and want to bring back all the posts for a certain post type then don’t forget to use the correct argument.

By default WordPress will use the number that’s been specified in the settings (the default is 10).

So, when your constructing your query be sure to include showposts in your argument – like so:

showposts => -1

I spent an hour working out why it was only showing 10 posts, so this post is so you don’t have to!

If you have any ‘duh’ moments (doesn’t have to be with WordPress) then please put them in the comments below as the chances are other people (me) have had them too!

Pagination with WordPress

There are lots of tutorials on the web about how to paginate your posts with WordPress – however there are probably more titled ‘WordPress pagination not working”.

It’s not that pagination is broken – or even that it’s difficult – it’s just some people don’t understand what they’re doing, maybe because a) they might just want to copy and paste it and hope it works or b) the tutorials aren’t that clear. So, here’s my attempt using the WP_Query class…

The Code

The first line of code you need is to detect which page of the query we’re on.

$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;

The $paged variable will detect which page we’re on and can therefore bring back the necessary posts. If we have 10 posts altogether and we’re showing 5 on each page and $paged is set to ’2′ then it will bring back posts 6-10.

$args = array( 'posts_per_page' =>5, 'paged' => $paged );

We then create our usual argument for WP_Query. The first argument is important as it stipulates how many results each page is going to display before having to use the pagination. Always include this and don’t rely on the number you have defined in your WordPress settings (default is 10).

$wp_query = new WP_Query( $args ); if( have_posts() ) :
while ( $wp_query->;have_posts() ) : $wp_query->;the_post();

We then create a new instance of WP_Query and loop through the posts as per our argument.

One thing that’s important to notice is that I’m using $wp_query to store the result.

I’ve seen people who have had problems using their own name such as $results. I would stick to $wp_query the first time round just to get the pagination working and then you can change it if needs be.

endwhile;

You will have your content and then of course end the loop. Only after the loop should you call the pagination. You can use these two functions to display it within your layout.

next_posts_link('Older Entries');
previous_posts_link('Newer Entries');

If you are on the first page of results then you’ll only get the ‘Older Entries’ as you are viewing the newest. So now you can browse through the archives of your posts. Don’t forget to end your if statement.

endif;

Advanced Usage

You may instead want to list the pages (e.g. [1] [2] [3] [4] [5]). WordPress does not offer this ‘out-of-the-box’ but there’s no need to reinvent the wheel because of this excellent pagination plugin. Simply install that and replace the ‘Older Entries/Newer Entries’ code with the following function.

wp_pagenavi();

Example

As you can see – pretty simple when it comes down to it.

Check out the the full code for WordPress pagination.

The code and tutorial is written from a working example but if you see any problems then please give me a shout or let me know in the comments!

CSS Child Selectors

There are times when you want elements of your site to act slightly different than normal, despite being restricted to using the same HTML markup.

Imagine a page with a header and three paragraphs of text. You want the paragraphs to be quite tight together (margin-bottom of 5px) but you want the first paragraph underneath the heading (a h2 for example) to be slightly bigger.

You could put a margin underneath the h2, but when you make the change it affects a whole host of h2′s on the site both in your sidebar and in the main content of the site – you wanted a simple change but instead this is going to take you 30 minutes to change and test – this is where selectors come in.

h2+p { margin-top: 10px; }

The CSS above would add a margin of 10px to the top of the first paragraph after the h2, better still it works in all major browsers (I don’t include IE6 in that)!

This standard has been out for a while now but it doesn’t mean to say everybody knows about it and of course there are much more complex things you can do with it, of which I would be interested to know how other people are stretching the CSS boundaries…?