Using WordPress As A CMS

wordle
Posted in Coding | Tags:
I’ll let you into a little secret. WordPress is a CMS. Arguably it’s a simple one, but it’s still a CMS; I’m currently writing my content and using WordPress as a system to manage my content. WordPress needn’t just manage content for my blog though. With pages and page templates you’ve got a quick and easy way of making a killer content management system.

In this post we’ll look at how to understand just how to use WordPress “as a CMS” effectively and efficiently.

Understanding posts and pages

This is key. Once you’ve got this it’s easy to understand how you can build more complex sites quickly. Posts are for blog posts, pages are for “static content”, something else I’ve never understood; just because it’s on a page doesn’t mean it can’t be dynamic; that’s what makes WordPress such a fantastic CMS: you make “static” pages and then fetch other bits of your content dynamically.

Essentially, posts are for blog posts and pages are for everything else.

Creating ‘dynamic’ ‘static’ pages

WordPress’ pages support things called page templates which are essentially special templates or designs which you can apply to each page. These make your ‘static’ pages ‘dynamic’ as you can then use the loop amongst other things to fetch your posts, perhaps using custom fields to get only the specific info you need.

Creating a page template is easy: just add

<?php /* Page Template: Name */ ?>

to the top of your file and it’ll be available immediately as a page template once you’ve uploaded the file into your theme’s folder. You’ll find these on the page editor page, by default on the right hand side. Choose it and save and your page will immediately have the specific page template, not the page.php file which pages have if there’s no page template set.

As I said earlier, your pages can have dynamic content, specifically anything that can run in a normal template file. That means loops (via a custom query) which you can then use to grab content off your posts (like custom fields), but we’ll come to that in a sec. First the custom loop:

<?php
    $customQuery = new WP_Query();
    $customQuery->query('posts_per_page=5');
?>
<?php while ($customQuery->have_posts()) : $customQuery->the_post(); ?>

<!-- Do query stuff here -->

<?php endwhile; ?>

This is just a simple loop that gets the five most recent posts, but you’ve got all the power of the loop at your disposal so can use any of the parameters to perhaps get posts with the custom field “show-on-page” by replacing posts_per_page=5 with meta_key=show-on-page. You can learn about the basics of WordPress theme design here.

Real-life application

We’ve now got a hypothetical shop and want staff to be able to add to a page the latest offers. Each offer is a post but we only want one line of text briefly describing the offer. We’ve built a custom meta box to allow an easy way of adding custom fields to posts. The custom field contains information about our latest offers.

We want to use a custom page template, custom loop and custom field in order to display a little section about the latest offers. We also want to show “no offers at the moment, check back later!” if there aren’t any offers set. Here we’re combining everything, with a little custom fields added in extra.

The full code could look something like this (of course this is in a custom page template!):

<?php
    $customQuery = new WP_Query();
    $customQuery->query('meta_key=show-on-page');
?>
<?php while ($customQuery->have_posts()) : $customQuery->the_post(); ?>

<?php $offer = get_post_meta($post->ID, 'show-on-page', true);
if ($offer) {
?>

<p class="offer"><?php echo $offer; ?></p>
<?php } else { ?>
<p id="no-offer">Sorry! No offers on at the moment, check back later!</p>
<?php } ?>

<?php endwhile; ?>

And that’s it. Hopefully now you’ll understand exactly how you can use WordPress to power just about everything! There’s really nothing complicated about making everything easier to use! Do share if you’ve got an ingenious application for this.

Image by Wordle.


23 Responses

Comments

  • Angie Bowen says:

    Very interesting and a great example to act as a jumping off point. I’d be interested in more posts on using WordPress as a CMS with more specific examples.

    • Alex Denning says:

      I’ll try and do something on that in the future. Ta for the suggestion :)

  • Randy says:

    I could not agree more! I have made many custom wordpress sites and only a small handful were actual blogs!

    When you think about it,most any type of organization or business probably needs a recent news or events section. That alone makes WP so handy for more than just “managing” some text or images.

    I cannot see a reason to ever push a client to have a static website when WordPress does so much out of the box.

    I think that most people don’t realize that a WordPress home page, or entire website, can look and do anything they want it to. They also don’t realize what the power of RSS means but they will soon!

  • I love WP. I think it’s great in many way for many things. But when it comes to this level of CMS’ing I believe there are better choices. For example, ExpressionEngine (http://www.ExpressionEngine.com). I do not mean to offend, not at all. But even your headline is “As a CMS” which kinda sounds like “Excel as a DB” or “Word as a CRM” .And how many time have we seen those mistakes.

    That said, good post. Thanks.

    Btw, not sure if you realized it or not but this Comment form doesn’t have any labels. At least no in my browser at the moment.

    • Alex Denning says:

      Not at all, I quite like hearing from people other than those who already use WP!

      I put the headline as it is because I hate hearing “WP as a CMS” — as I try and point out at the start, it is a CMS, it’s just it isn’t an advanced one unless you want it to be which makes it fantastic.

      What browser are you using?

  • Sara says:

    Great simple article, I use WordPress as a CMS all the time for my clients, it’s great.

    One nagging problem I have is that if you don’t make the blog your front page, it’s very tough to send people to the blog with proper “Older Posts” and “Newer Posts” navigation — or if it’s easy, I haven’t figured it out yet! I have to set up a custom-coded link to “Blog” in the navigation, which goes to http://domainname.com/page/1 — and then I usually have to create an alias using .htaccess from http://domainname.com/blog to that page/1 url.

    Oi! It’s far from perfect. If you know a better way, I’m all ears!

    • Alex Denning says:

      If you’re just running a standard loop then you don’t have to do anything extra to get the navigation — the standard should work just fine.

  • iris says:

    Great article, thanks!
    I’m even using WordPress to manage Flash-sites. Works like a charm.

  • Andy Kinsey says:

    This is a nice post, but lets be honest there is not much too hard about making WP into a CMS … you just need a little confidence in how you do things and of course the odd site like this ;)

    • Alex Denning says:

      That’s more or less the message I wanted to portray — it’s as easy as splitting up your HTML into a couple of files!

  • Rilwis says:

    In this post, I love the ‘dynamic static page’ term :). It’s amazing feature of WordPress, that helps us very much to create custom page template. Using only this feature, WP has already ability of a basic CMS like some other open sources software.

  • The next WordPress release will lean more towards the CMS, and less to the blog, making content types possible (for example ‘movies’, ‘actors’, ‘books, ‘authors’) than only a ‘post’ or ‘page.

    Looking forward to this very much!

  • Bart Hook says:

    WordPress is a very powerful CMS. I have been using it for my freelance clients for years. Recently I was able to convince my employer of it’s capabilities.

    Bart

  • I have been putting a lot of work into this direction.
    I built my site in actionscript 3 using a framework i’ve mad called WPMVC. it utilizes the page template property to map something like “article.php” (which is a wp page template i added to my theme) to a class called Article that extends Sprite. All of these template classes have internal logic for parsing the page’s content and displaying it in my Flash movie. Other templates i have, like one called “RowGroup” actually parses and displays the contents of the templated page’s child pages. Check out my site to see what WPMVC looks like on my site, then disable Flash or visit with an iPad to see the underlying WordPress site. the non-flash theme is a generic one i created called FlashFrontEnd which handles the embedding code, but is currently ugly and doesnt really display the content correctly without flash, but you can see the potential to have a multi-multi-platform Site running off of WordPress.

  • James Macfie says:

    I couldn’t agree more – I love WordPress for it’s simplicity and scalability. And 3.0 with it’s custom pages it going to make things a lot more interesting. Excellent article

  • Bart Hook says:

    Found a nice little snippet of code today that I thought I would share. It allows you to put a specific post on any page or in any template.


    array(47),
    'post_type' => 'post',
    'post_status' => 'publish',
    'posts_per_page' => 1,
    'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
    while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <a href="" rel="bookmark" title="Permanent Link to ">

  • Thanks for info and code!

  • Shilpa says:

    Hello,

    Very good article and its helpful to understand WP.

    I recently migrated to WP from blogger and trying to find a way to make my pages dynamic as I am writing novel.

    But unfortunately WP pages are static unlike the home page which gives option to move between older and newer posts from the post I am reading in. Any idea how I can incorporate the same for my pages..

    Would appreciate your kind help!!

  • Danny Walker says:

    The great about WordPress is the user base, And the way one easily can make plugins for it, and with allot already available. I’m currently using it for a remake of an old non WordPress site, this site will be quite advance, with allot of pages round 5000+ when finished, we’ll see how it will hold up on this scale.

Pingbacks

Shares
Share This

Share This

Liked this post? Help us by sharing it!

Shares