Turn WordPress into a CMS
I love WordPress; it truly amazes me sometimes. The out-of-the-box setup has a lot to offer and for most users will be all they ever need to start blogging on the interwebs. Sure you may choose to add a few snippets of code into the functions.php
file here and there, but general with a little amount of work you can have a site up and running in no time at all.
That said, WordPress has a lot more to offer than a simple blogging tool. With a few steps we can create a Content Management System, with features that would make other off-the-shelf solutions blush.
That’s why I thought I would put together a post on some of these exciting features you can add into WordPress, based on my ever increasing exposure to a variety of plug-ins and PHP snippets available:
Change the login and dashboard logo
It can often be the little touches that make a big difference. This is a simple little snippet of code that, when added to your themes functions.php
, will allow you to change the logo on the WordPress login and dashboard page.
function custom_login_logo() { echo '<style type="text/css"> h1 a { background-image:url('.get_bloginfo('template_directory').'/images/login_logo.png) !important; } </style>'; } add_action('login_head', 'custom_login_logo');
function my_custom_logo() { echo ' <style type="text/css"> #header-logo { background-image: url('.get_bloginfo('template_directory').'/images/custom-logo.gif) !important; } </style> '; } add_action('admin_head', 'my_custom_logo');
This will add a little personal touch to a site, which would otherwise have the default WordPress logo. Do make sure you match the width and height of the new images to the originals though (326px X 67px and 32px X 32px); otherwise it will it is not a simple image source change and will therefore require a little more work.
Enable page excerpts
Excerpts can be very handy, but strangely WordPress has decided to disable ‘Page Excerpts’ by default. However, a simple tweak to functions.php
and they are back!
add_post_type_support( 'page', 'excerpt' );
Page excerpts can be really handy for using on related pages, listings or even as the page meta description, which could aid SEO if used properly.
Upload page attachments
This is a by far one of my favorite plug-ins by Jonathan Christopher. It allows you to associated attachments to a page, for example we might want a product page with multiple photos of the product to appear in a carousel. With this plug-in we simple upload the images and attach them to the page!
In this case we would simple output the attachments in our template :
<div id="attachments"> <?php $attachments = attachments_get_attachments(); $total_attachments = count($attachments); ?> <?php if( $total_attachments > 0 ) : ?> <ol> <?php for ($i=0; $i < $total_attachments; $i++) : ?> <li> <h3><?=$attachments[$i]['title']?></h3> <p><?=$attachments[$i]['caption']?></p> <p><small>Attachment ID: <?=$attachments[$i]['id']?></small></p> <p><code><?=$attachments[$i]['location']?></code></p> <p><?=$attachments[$i]['mime']?></p> </li> <?php endfor ?> </ol> <?php endif ?> </div>
Example taken from http://mondaybynoon.com
Create custom post/page types
Now we are getting into the more CMS admin related features. Here it must be stressed that “With great power comes great responsibility”. First up – Creating custom content types with the Custom Type UI plug-in.
This plug-in does exactly what you would expect; it enables you to create and edit new content types, such as “FAQ’s”, “Products” or whatever you like! You can completely customise which of the default field you wish to enable such as Title, Content, Except, Tags etc.
Ultimately this means we can begin to break down the content to avoid creating everything as a “Post” or “Page”. Sure, you could do this without a plug-in, but Custom Type UI makes it a LOT easier to manage.
Add more fields to post/page types
Following on from Custom Type UI, now that you have your custom types such as “FAQ’s”, maybe you want to add additional fields such as “citation” and/or “question”. Content types that are not part of WordPress core fields. Well, unsurprisingly there is a plug-in for that too! The Advanced custom fields plugin will allow you to create additional fields and add them to a default or custom content type.
To use the new field, all you need to do then it add the custom meta field to your template:
<?php if ( get_post_meta($post->ID, 'question', true)) : ?> <blockquote> <?php echo get_post_meta($post->ID, 'question', true) ?> <?php if ( get_post_meta($post->ID, 'citation', true)) : ?> <cite><?php echo get_post_meta($post->ID, 'citation', true) ?></cite> <?php endif; ?> </blockquote> <?php endif; ?>
With the help of two plug-ins we can now easily create new content types and add custom fields to them!
Create templates with unique field
Great! So far we can create new content types and add new fields to them. But what if we want to have two or more variations of a content type. Sure we could create “FAQ’s v.1” and “FAQ’s v.2” but that’s a little counter intuitive. This is where the Custom Field Template plug-in comes in!
This plug-in allows us to create custom fields for specific templates. So for example, we could have a content type called “Products” with several “product” templates, each template can then have a different set of custom fields allowing us to easily create product pages with different information/custom fields!
Alternatively, this plug-in also allows us to add multiple editable areas to a template. For example, you might have a site with a “Homepage”, “Landing Page” and “Content Page”, where you have 6 editable areas in the Homepage template, 4 editable areas in the landing template and 2 editable areas in the content page – all created as pages but each template loading a different set of custom fields using the plug-in.
Automated XML sitemap generator
There are several ways you can add an XML sitemap to your website. The XML sitemap plugin is one of the best and easiest to setup I have found. It will generate an XML sitemap that will help search engines like Google, Bing, Yahoo and Ask.com to better index your site.
The plug-in automatically updates the XML when you create a new page or post. Sadly, at present the plug-in does not support user generated content types such as our “FAQ’s” example, but be assured it is on the plug-in development roadmap.
If your interested to see what it does, take a look at the sitemap on my site (Bests viewed in a browser that parses XML).
Add a contact form
A final mention, though it bears little relation to CMS’s specifically, to the Contact Form 7 plug-in. This is one of the easiest to use and most configurable Contact form plug-ins I have found. Sure you could create a specific function or template to handle a contact form yourself, but this plug-in allows other to edit it easily from within WordPress admin.
There we have it – a couple of tips, code snippets and plug-ins that can start to turn WordPress into more than just a blogging tool.