Tag Archives: wordpress

WordPress 2.9 e-Commerce

6 Mar

WordPress 2.9 E-Commerce WordPress 2.9 e-Commerce, has been published – the definitive guide to setting up an e-commerce site on your Wordpress blog using the WP e-Commerce plugin, of which I’m a bit of a fan.

This book provides an easy to understand, step-by-step approach to installing, configuring, and using WP e-Commerce to run your online store. We will construct an example store in the book with enough information and flexibility to adapt the store to your specific needs.

This book is for you, if you are interested in using WordPress as the basis for a store that can sell physical items, downloads, or services. It is ideal for a sole proprietor or small business owner with only basic, in-house technical skills. Some prior knowledge of WordPress will help, but is not required. No knowledge of PHP is expected, but it will be helpful.

You can buy it from Amazon here.

Disclaimer: I’ve linked to Amazon using affiliate links, to help fund this blog.

Getting URL of Post Thumbnails in Wordpress 2.9

29 Jan

One of the improvements in Wordpress 2.9 is native support for thumbnail images on posts. The API is pretty good – although it assumes that you want to return the whole IMG tag. In my case I wanted to return the URL of the image (So I could wrap the actual thumbnail in a lightbox-style link to the larger versions).

So – if you want to get the URL of your posts thumbnail – here’s the code you need:

$image_id = get_post_thumbnail_id();
$image_url = wp_get_attachment_image_src($image_id,'large');
$image_url = $image_url[0];

I hope this helps you with your theme development.

How to Split Test Wordpress Themes

17 Oct

I recently re-worked a site for a client. He was moving over from Joomla to Wordpress, so I started from scratch with his theme design. They liked the new theme I came up with – however I’d put the menu and other navigation (Links to recent articles, etc) in a right hand sidebar, and they weren’t too sure about that.

“Doesn’t everyone have the menu on the left?”

Now I’m no usability expert, and while I figured they were probably right I thought we’d run a little experiment. I trawled around a bit, and I found a nice little post by David Dellanave. While I was OK implementing David’s solution I though it was probably a little complicated for some of my other clients, especially when it came to running 3 Google analytics accounts – so I did some digging.

The result is the SES Split Testing plugin.

To use the plugin you’ll need to be using Google Analytics tracking on your Wordpress blog already (If you’re not, then I’d recommend the “Google Analytics for Wordpress” plugin), then :

  • Create two (or more) versions of your theme
  • Select them in the plugin settings
  • Define custom segments in Google Analytics
  • Sit back and watch the results roll in

Create theme variations

In most cases, you’ll want to test two versions of 1 theme with some slight changes. Let’s assume your theme is in the folder wp-content/themes/mytheme. Take a copy of your theme and put it in fresh folder, e.g. wp-content/themes/mytheme_2. Open up the style.css file in the second folder, and change the Theme Name, e.g.

/*
Theme Name: MyTheme
*/

to

/*
Theme Name: MyTheme (v2)
*/

Set up plugin settings

Wordpress Theme Split TestingNow you can drop the plugin into your plugin directory, activate it in the Wordpress backend, and then go to the settings page (Settings->SES Theme Split Test). The plugin will list all of your available themes, and you can choose which ones you want to be part of the test.

Once you’ve saved the settings, the split testing will kick in. Visitors will be randomly assigned one of the chosen themes, and they’ll receive that theme any time they visit in the next 30 days. Not only that, but their visit will be tagged with a special variable that you can pick up on in Google Analytics.

Set up Custom Analytics Segments

Google Analytics lets you define custom segments (Ways of grouping customers). In this example we want to group customers according to which theme they were shown and then we can measure our chosen metric (Purchase / sign-up / page views – whatever) for the two groups and compare them. To get started, you probably want to wait 24 hours so that Google starts to receive the tagging data.

Setting up custom segmentsLog into your analytics account, and click on the “All Visits” dropdown (Top-right, just above the date selector), and then choose “Create a new advanced segment”. Then, you want to expand the “Visitors” dropdown under “Dimensions”

Custom Segment Build

Scroll down until you find “User Defined Value” and drag it onto the right hand box that says “dimension or metric”. If Analytics has got your tagging data (See – I told you to leave it 24 hours!) then you’ll get to choose from the values being passed, e.g.

Analytics Custom Segments

Create a segment for each of your themes, and give them a meaningful name, then you’ll be able to select them as custom segments in your reports.

Segmented Analytics Reports

Now it’s just time to wait, see what happens, then decide. Once you’ve got a winner then just set that as your blog’s standard theme in the normal way, and either deactivate the plugin, or unselect the themes in the settings and users will see the blog default.

How to write an application for Wordpress

7 Sep

I’ve recently been doing some work for a family member on a Wordpress blog they run, and the need came up to build a mini-app. Now historically, I’m a Joomla kind of guy, and it’s fairly clear that for a Joomla site you would build a component to implement your app.

However, in Wordpress it’s a little different. I’ve found loads of articles about available API calls, manipulating “the loop” and all sorts of useful information. What I haven’t found though is something that explains at a fundamental level how I should approach the problem.

There isn’t a concept of an “application” under Wordpress, the only items that are accessible are “posts” and “pages”. As far as I can tell, I have two options:

  1. Publish a post/page with no content other than a special string (E.g. [my-app]) and then write a plugin that filters post content and replaces the magic string with the output from the application
  2. Create a page, and assign it a custom template. Implement your application in that custom template

Option 1

It works, I know because this is what I did :)    However there is a performance penalty, your application code is called on every post, and so you have to take steps to make sure it doesn’t run unnecessarily. The other disadvantage is that well, it just doesn’t seem clean.

Option 2

This seems a little nicer, but doesn’t really fit with Wordpress’ nice plugin installation architecture – as far as I can tell plugins can’t auto-install into the current theme directory, and custom templates can’t live anywhere else.

So, this leaves me a little confused – can anyone point me as to how I should have solved this problem – or does Wordpress need to grow up a little and add “application” alongside posts and pages?

Tracking Twitter Traffic Redux

7 Aug

I wrote a previous post about how you could hack the excellent Twitter Tools plugin from Alex King to add Google Analytics tracking variables to the URLs posted to twitter when you posted a new blog post.

I submitted the patch upstream, and Alex kindly pointed out that rather than bodging around in his code – you could achieve the same effect with a filter.

So, here it is. Simply download this file and save it in your wp-content/plugins directory. Activate the plugin in your Wordpress backend (It will be listed as “Twitter Tools Tagger”) and away you go. Whenever the twitter-tools plugin tweets about one of your blog posts, the URL will be tagged with analytics tracking.

As an added bonus, version 2.0 of Alex’s plugin can also pump your URLs through the http://bit.ly/ URL shortening service so your URLs will be tagged, and shortened.

So, that’s nice.

Custom Taxonomies In Wordpress Plugins

7 Aug

Taxonomy Support

I wrote recently about building a brand directory using a fantastic feature of Wordpress called “Taxonomies”. Now that that feature is live I’ve realised that a number of my favourite Wordpress plugins simply don’t support taxonomies.

Among the casualities were Google XML Sitemaps, and the otherwise excellent Headspace2.

Now, the beauty of open source is that when you get an itch like this, you can go and scratch it. So, I whipped out my coding gloves and set to work.

The results are below:

Google XML Sitemaps

The patch below will ensure that the pages for all of your taxonomy terms are listed in your sitemap – helping Google find the pages quicker.

http://www.leewillis.co.uk/patches/google-sitemap-generator/include_taxonomies.txt

HeadSpace2

The patch below lets you add %%term_description%% so you can populate your META tags properly on your term pages – great for us and our product directory.

http://www.leewillis.co.uk/patches/taxonomy_support_for_headspace/patch_v2.diff

Both of these have been submitted to the plugin authors – so hopefully they’ll get included by default in a future release. If you find them useful – please add to the threads here:

Google XML Sitemaps

Headspace2

Using Wordpress taxonomies to create a product directory

31 Jul

Background

Wordpress lets you categorise your posts according to “tag”, and “category”. Which is fine. However, for some time now Wordpress has supported a concept called “Custom Taxonomies”. Which is a long winded way of saying “We’ll let you choose how your organise and present your posts – however you want”.

This isn’t something I’ve ever felt the need to use before (I’m happy enough with tags on this blog) – however having used them recently I’ve really begun to appreciate how powerful they are – and I’m amazed that more people don’t use them to create a more sensible structure to their Wordpress sites.

That said, I’m a bit of a geek, who’s not averse to diving into code, and isn’t intimidated by a set of cryptic API documentation :)

The Business Case

So, what can taxonomies do for you?

The site I built this for is a resource all about baby slings, the different types, the different brands, and people’s experiences, of finding, choosing, and using them.

Tagging just seemed to create a big, hard-to-navigate tag cloud that didn’t create an easy way for people to find the right content on the site that was going to be useful to them (Feedback has suggested that people are either looking for information about a particular brand, or a specific type of sling irrespective of brand).

The How-To

So, out went the “tags” (We removed them from most old posts, don’t add them to new posts, and got rid of the “tag-cloud”). Next step was to install Joost de Valk’s Simple Taxonomies plugin. This is one of Joost’s simpler plugins. In general all it does is let you create a taxonomy, and manage the terms within that taxonomy.

Actually, as an aside – I suspect this is why custom taxonomies haven’t really taken off. Out-of-the-box you have to create code to set them up and use them for effective site navigation. If the functionality provided by Joost’s plugin was in Wordpress core, and theme authors really started coding for this stuff, I’m sure it would fly, but I digress …

So, using the plugin, we created two taxonomies – “Brands”, and “Sling Types”.

Taxonomy Settings

Next step was to go back through our posts (Fortunately this was in the early days of the site!), and correctly “tag” the posts against the right taxonomies. So on the SnugBaby review, we set the “Brands” to “SnugBaby”, and the “Sling Types” to “Mei Tai”.

Tagging Taxonomies

Now we’ve got all of our posts beautifully organised, but we don’t have a way to view them. Before we get to that though, there’s just one more step. For every “term” (ie, for every brand, or sling type) we need to provide a description. Your new taxonomies can be found in the “Posts” section of the Wordpress backend, simply click on the taxonomy, e.g. “Brands”, then work your way down the list adding a useful description.
Taxonomy Descriptions

Now we can actually start presenting this information sensibly!

Theme Work

Now, we’re going to use that list of “terms”, and their descriptions, to create a top-level list of “brands”. Download the file below, and save it in your Wordpress theme directory. We called it “brand-directory.php”, but the name doesn’t really matter.

brand-directory.php

This will create a new page template called “Brand Directory” (If you want to change the name, edit the comment at the top of the file).  Now create a page in Wordpress, provide some content that you’d like to use as an introduction, and set the page template to this new file:

Set Page Template

Basically all this file does is display the page content you created:

<?php the_content(); ?></p>

followed by each one of the terms that you’ve used, along with it’s description:

$terms = get_terms(‘brands’);

foreach ($terms as $term) {

echo $term->description;

and a link to all of the posts that have been assigned to that term:

$wpq = array (‘taxonomy’=>’brands’, ‘term’=>$term->slug);
$query = new WP_Query ($wpq);
$article_count = $query->post_count;

if ($article_count) {
echo “<a class=\”taxonomy-rel-link clearfix\” href=\”/brands/”.$term->slug.”\”>”.$article_count;
} else {
echo “<span class=\”taxonomy-rel-link\”>$article_count”;
}

echo ” related article”;
if ($article_count!= 1) echo “s”; else echo  “”;
if ($article_count>0) {
echo ” – click to view</a>”;
} else {
echo “</span>”;
}
echo “<br />”;;

And there you have it, a dynamic data driven directory that keeps itself up to date whenever you “tag” a brand – all you have to do is add a description for the brand!

For an example see the “Get Your Hands Back!” brand directory here.

10 Essential Wordpress Plugins

18 Jul

I’ve been meaning to write this post for a while, but I’ve recently had to build a new Wordpress site from scratch, and I’ve also had a couple of friends ask my advice on how to get their own sites up and running – so I was spurred into action.

This list is my ten “essential” plugins, that I think every wordpress site needs, and they all get installed straight away on any new site I build, so here they are in no particular order…

Akismet

Akismet checks your comments against an online web service to see if they look like spam or not – and if you ask me it does a great job. If your site gets in any way popular then you will need this plugin. It comes bundled with Wordpress so there’s really no excuse for not enabling it.

Google Analytics for WordPress

A great plugin from the Wordpress expert Joost de Valk – this allows you to easily add Google Analytics tracking code to your blog. You can download it here.

Google XML Sitemaps

This tool allows you to automatically create an XML sitemap suitable for submission to Google Webmaster Tools. An excellent opportunity to see how your site is being indexed and found by users.

HeadSpace2

Probably the most difficult to set up properly of the lot, Headspace2 describes itself as a “meta-data manager on steriods”. By default Wordpress generates meta descriptions and keywords itself, but it often can’t do a great job (After all – you can probably summarise your article better than a computer – right?). Headspace2 lets you set sensible defaults for page titles, and meta-tags, and then offers you to override them for each post allowing you to put in meaningful descriptions, and keywords, and set SEO-friendly titles.

Robots Meta

This plugin offers an easy way for you to control your robot meta tags. For the uninitiated this means you can choose which of your archives (Date, Author, Category, Tags etc.) can be indexed by Google – allowing you to choose the scheme that makes most sense or your site navigation.

Secure Wordpress

This is a fairly simple little plugin that takes care of hiding bits of information in the background of your site that might otherwise make your site easier to attack – and no one wants to deal with a hacked site do they! Get it here.

Sociable

Another simple plugin – it adds social bookmarking buttons to your post so that your readers can share your musings with their friends, colleagues, and the rest of the Internet too. It offers a great selection of social sites, so you’ll be sure to find a set that match your business.

Subscribe2

This plugin allows your readers to subcribe to updates via email – receiving an email every time there is a new post or page. This is an essential plugin if your audience is non-technical and wouldn’t know their RSS from their elbow …

Subscribe To Comments

If people comment on your posts, then they’re starting a dialogue – one that you’ll want to continue. This plugin lets people receive notifications when other comments are made against a post they’ve commented on. There are other options for this sort of functionality (Disqus, Intense Debate etc.) – but this is a good option that works well.

Twitter Tools

An excellent tool that lets you join up your twitter following with your blog, turning blog posts into automatic tweets, and letting you feature your tweets in the sidebar of your blog. You can get the plugin from here – although I’d also recommend checking out my previous post about how to track your twitter traffic so you can tag the tweets it produces with Google Analytics and you can see how effective it’s being.

Roundup

If you get all of these installed and set up you’ll have the basic of an SEO friendly blog which will allow your readers to interact with you how they want – now you just have to write engaging content!

Tracking Twitter Traffic

24 Apr

Twitter is a revolution

So, Twitter is a revolution (Apparently). The important thing about Twitter isn’t that you can find out what Stephen Fry had for lunch, or when Oprah is having her makeup done. No, the important thing, for people trying to use Twitter as a a weapon in their digital marketing arsenal, is that Twitter traffic is 10x higher through their API, than through their website.

What is Twitter doing for you?

So what does that mean for Average Joe Ltd. trying to engage with his customers in a brave new digital world?

Simple – links that you post are likely to get read on a mobile phone, or in any one of hundreds of different desktop clients . There’s every chance that if someone clicks through to your site you will have no idea that they came from a Twitter link (Desktop clients particularly tend not to send the all-important HTTP-Referrer information).

So – what’s to be done?

For SnugBaby, as well as twittering as a normal user, we use the excellent Wordpress “Twitter Tools” plugin to tweet when we update our blog. So – how to track how much traffic we were generating from these links? Fortunately there’s a fairly straightforward solution to the problem. We analyse our traffic using Google Analytics, which provides the ability to “tag” links with extra information. This is commonly used to track inbound links relating to specific marketing, or email campaigns – but we use it to track Twitter as a campaign all of it’s own. This is nothing new.

However – our blog-related links are tweeted automatically – so we needed to make some changes to the Twitter Tools plugin to add on the tracking codes.

The Solution

For those that are interested I’ll step through the changes below – but if you want a quick twitter tracking fix, then you can download a patch (Against version 1.6 of twitter tools), or a complete copy of the twitter-tools.php file.

Step 1. Flexibility is king

We want to make our solution a little bit flexible, so we set up the tagging as a setting which can be controlled through the Wordpress admin pages. We called it extra_query_args:

Line 120-146:
	$this->options = array(
			'twitter_username'
			, 'twitter_password'
			, 'create_blog_posts'
			, 'create_digest'
			, 'create_digest_weekly'
			, 'digest_daily_time'
			, 'digest_weekly_time'
			, 'digest_weekly_day'
			, 'digest_title'
			, 'digest_title_weekly'
			, 'blog_post_author'
			, 'blog_post_category'
			, 'blog_post_tags'
			, 'notify_twitter'
			, 'sidebar_tweet_count'
			, 'tweet_from_sidebar'
			, 'give_tt_credit'
			, 'exclude_reply_tweets'
			, 'last_tweet_download'
			, 'doing_tweet_download'
			, 'doing_digest_post'
			, 'install_date'
			, 'js_lib'
			, 'digest_tweet_order'
			, 'notify_twitter_default'
			, 'extra_query_args'
		);

We also provide a sensible default for people installing the first time:

Line 178:
$this->extra_query_args = '?utm_source=twitter&
utm_medium=twitter&utm_campaign=twitter';

The final step is to build the form that will let users change the value of the new parameter:

Line 1580:

<div class="option">
  <label for="aktt_extra_query_args">'.__('Text to tag on
the end of URLs in generated tweets', 'twitter-tools').
'</label>
  <input type="text" size="30" name="aktt_extra_query_args"
id="aktt_extra_query_args" value="'.$aktt->extra_query_args
.'" />
  <span>'.__('Include the leading ? before query args',
'twitter-tools').'</span>
</div>

Step 2. The magic bit

The final change simply adds the contents of your parameter onto the end of the post URL before passing it off to the URL shortener.

Line 466:

$url = $url . $this->extra_query_args;

Job Done

And that’s that. Twitter tools will now post URLs that include tracking information – all you have to do know is keep an eye out for them in Google Analytics!