Here you will find my multi-part series on WordPress CMS in one location. No longer valid as of WP 1.5+
In this tutorial we will cover the steps necessary to use WordPress as a CMS. This tutorial will cover the basic concepts and steps to get something up and running as quickly as possible, part 2 will cover more advanced tricks to get the most out of your WPCMS.
The first step is to identify exactly what you want to get out of a CMS, just because you can make WordPress function as a CMS doesn’t mean you should. Be sure before you begin that you are not creating more work for yourself than neccessary.
Okay so I assume since you are still with me that you have decided that a WPCMS is for you. Now, we need to identify how your new shiny sight will be organized. For the purposes of this tutorial lets assume that you will have the following site structure:
The core of our approach will be to utilize the category system built into WordPress to “fake” static areas of your site. First off, create the new categories that correspond to our “sections”. Go ahead and do that, I’ll wait.
Done? Good, now we need to go to our index.php page and make some changes to how we grab and display our categories to the world. But first things first; we need to find out the id number of each of our new categories, so off to ~/wp-admin/categories.php! Once there, locate the categories we have added and take note of the id, for our purposes we will assume they are 8,9 and 10.
Now having our id’s we open index.php in your favorite editor and add the following to the top of the file just below$cat="1 2 3 4 5 6 7";Edit: Now you might be asking your self as one of my readers asked me already, why not just use $cat = “-8 -9 -10”; instead of listing the allowed cats? Well as I responded to him, currently in WP you can only have one negative value in the $cat=”“; statement. This might be something that will be changing in the future, but until then the only way you can make the magic work is to follow my instructions.
So the top of your index.php page should now look like this:<?php
$cat="1 2 3 4 5 6 7";
require('./wp-blog-header.php');
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="eng"><head profile="http://gmpg.org/xfn/1">
What we have just done is tell the index page to load any content it finds in categories 1 -7, but to absolutely, positively ignore 8 - 10. Now this is a good solution when you have multiple categories that you want to exclude, but if you only have one, say you only want to have an aboutme.php page, then you would simply place this: $cat = “-9”; which would tell your index.php page to pass over any posts that belong to the aboutme category. Pretty simple huh?
Now on to your single category pages, e.g. colophon.php, aboutme.php and reviews.php. These are even easier than setting up your index page. Remember those id numbers you grabbed to exclude from index.php? Now you need to add the appropriate category number to each page. For this example lets assume that the cat id’s correspond to the category names in the following order:
<?php
$blog = 1;
$cat="8";
require('./wp-blog-header.php');
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="eng"><head profile="http://gmpg.org/xfn/1">Now save this page as colophon.php and you are officially done with setting up your colophon. Now you can easily log into your wp-admin area and create as many entries as you would like for the colophon, and they will magically appear on colophon.php but never show up on index.php. Do this for each of your other pages changing the $cat=”(n)”; to match whichever category you are wanting to echo out on that page.You really have nothing left to do for your individual pages, so we can move onto cleaning up a couple of loose ends on index.php. You have very sagely removed any post content that corresponds to your new categories from index.php, but neglected to do something about your categories list on index.php! Now this only applies to those people who have not seen the light as I and a few others have, and still have categories listed on your index page. But I digress, back on topic.
So we now need to ensure that our category listing on index.php only shows the categories that we had specified with $cat=”blah balah”; and yes I meant to write blah balah, it is fun to say you should try it sometime. So lets open index.php again if you closed it and locate this snippet of WordPress code:<?php wp_list_cats(); ?>You should find it around line 71 or so, and change it to this:<?php wp_list_cats('exclude=8,9,10'); ?>Now of course you would want to change the id values to whatever your cat id’s are, but you already knew that didn’t you?
Well that is it for now, you should now have a working CMS system powered by WordPress. In part 2 I will cover semi-caching of your pages to increase speed on those pages that are not always changing, and how to perform some nifty magic with your apache server. See you then.
Now we comes the part where we throw in some cache-action. Brought to you by the Dynamic Duo Mattman and Zeller the Boy Wonder. Now Staticize Reloaded is not the best thing since sliced bread, but it is pretty great regardless.
Now I am not going to get into the “how” the plugin works, I mean who wants that! We are Americans, we just want it to work now! So anywhoo, follow these easy steps to set up a little cache action:
Okay so now we have our pseudo-static sections caching (as well as our non-pseudo-static sections), so what is the next weapon to add to our arsenal? Read on and find out.
The next part of this tutorial requires you to be able to make changes to your apache setup, either through editing of httpd.conf or through .htaccess. Sooo… if you can’t do one of these two things, please skip ahead. Those of you still with me, lets get to the hackin! What we are trying to accomplish here is to add some flare to our newly created and cached sections. Most sites that have aboutme and colophon sections use a site uri something like this: mysite/colophon/, now our solution poses a problem since they are not files in sub-domains, they are php files residing in our $siteroot, or wp directory. There are two ways to approach this:
So, what we need to do is fire up the old terminal and edit either httpd.conf or .htaccess. I will let you find out where these files are located since each distro handles placement differently. For this haxie we simply need to add this snippet of code:<Directory /home/www/sitename/htdocs>Options + MultiViewsto your httpd.conf file or your .htaccess and then once saved, restart apache. I prefer the lovely:
</Directory>apachectl gracefulcommand to restart apache, since it politely kills the child processes instead of just hacking them off wholesale. ; Now there could be a performance impact by doing the above, but unless you are running with a couple million hits a day, it is minimal.
Okay now we have our site running without file extensions, and caching. So what is left? Good question, to close I wanted to suggest some cosmetic changes. On our pages like aboutme and colophon, we really don’t want to have people leave comments, and we don’t really need to display the time, day, category and author for each of these “entries” so we should get rid of those function calls. Keep in mind that what we might want is a last updated on bit of code, that would find the date and time for the newest entry on that cat and echo it out.
That can be accomplished by using a bit of custom code, or by exploiting some of the functions already built into WordPress. That my friends is your homework. Well that is it for now, let me know if there is anything else you would like to hear on this topic, or if anything I have stated is not as clear as it could be.
Cheers.
There are currently no comments, why don't you leave one?
Pingbacks & Trackbacks
Leave a Reply