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.
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.
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.
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!!
Thanks for info and code!
[…] On our current example, on each post that we want play as page, we only need to added custom field this-is-page. If you need real example for this tricks you check it on WP Shout. […]
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 ">
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
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.
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
[…] Using WordPress “As A CMS” [WPShout] […]
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!
[…] USING WORDPRESS “AS A CMS” […]
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.
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 😉
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!
Great article, thanks!
I’m even using WordPress to manage Flash-sites. Works like a charm.
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?
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.
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!
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.
I’ll try and do something on that in the future. Ta for the suggestion 🙂