Using Wordpress as a CMS and a Blog
About six to eight months ago I found myself having problems getting enough time out of the day to manage a custom website for Weberz on top of fixing servers, answering support tickets, and generally trying to conduct business on a day to day basis. So I decided to look into making at least one of those jobs easier by converting our website to be managed by a Wordpress installation. The general idea was to use Wordpress as a CMS system and a blog platform in a single installation of the software.
The reason behind making such as change was simple. Wordpress has such as huge following that the internet community at large has created plugins and themes for the system for almost every possible need. This is great as it allows us to use those plugins rather then having to code custom pages in PHP on our old website to get similar features.
During my journey I found out that using Wordpress as a CMS was not a difficult task. I made plenty of mistakes along the way and it was a little bit of a bumpy road, this was mainly due to the lack of information regarding the problems I was having on the internet. I will cover all these problems below and hopefully they will ease the pain for others in search of answers.
Here is what I wanted out of the system.
- Wordpress is made up of posts and pages. Posts are normally displayed in chronological order and thus work extremely well for the blog entries. Pages carry more of a static content look and feel, leaving them as the optimal choice for the “website” outside of the blog.
- Wordpress should be installed in the root of our domain “/” and the same installation should work for “/blog” where our blog will be located.
- The entire setup, site and blog, should use the same plugins and themes so we get the same look and feel throughout the user experience.
- The front page, or main domain page, should look different from the other sub pages on our site. Example: http://www.weberz.com looks different from http://www.weberz.com/network
- All of the blog posts and information should be located under the posts page, or home page in Wordpress code speak. This is so the users and search engines can easily tell our blog area’s from the main website.
Now the above may seem like a lot, but its really not that bad. That is of course once I figured out how everything goes together and works. With that in mind… Here’s how it all works.
The CMS & Blog Setup
I installed Wordpress into the root domain folder just as I specified above. I setup the configuration file and did a little trimming of the default entries in the database. These included changing the admin password, removing the links, removing the about page and removing the hello world post. Once all that was done I simply created two new pages in Wordpress. One I named “main page” and the other I named “blog”. For both of the pages I left the content blank and simply typed in the title for the page.
Once I had the two pages setup I was able to go to the Settings -> Reading page and found the option labeled “Front Page displays“. I changed this to the “A Static Page” option. Once I had those set there were two drop down boxes that could be used to select which page was the front page and which was the posts, or blog, page. I selected the proper pages and saved the options at the bottom.
That was all there is too it. At this point the page I named “main page” is now the main website home page and the page I named blog is now where my blog posts will display. They result into the following URLs:
Main Page: http://www.domain.com
Posts Page: http://www.domain.com/blog
This was perfect! I thought it could not get any simpler then this.. I was right.
Changing the Main Page’s Design
This one was a little more difficult. According to the codex document for Wordpress Pages, I am able to specify a different template/page layout for a page. So what I did was make the default layout for pages be what I wanted all the sites sub pages to look like. I did this by editing the template files and CSS design. The end result turned out to look like our network page.
The main page however I wanted to be different. So I designed a new layout in a template file and placed the following at the top of the PHP file:
/*
Template Name: Index Page
*/
This designated the template file as a special page template called “Index Page”. Once the design for this template file was done, I was able to go back into the Wordpress administration and edit the page I previously created called “main page”. On the right of the page editing screen there was an option for “Page Template”. In the drop down there was a template called “Index Page” which changed the design of only this page to the new layout I had created.
Between those two items we pretty much covered most of the requirements above. The last one was the largest pain and caused me the most headache. That was the requirement of wanting all of the blog information to stay under the blog directory. What I mean by this is that I wanted all the URL’s for tags, posts and categories to be located under “/blog/” where the posts page, or home page, was specified to be.
Tag and Category Base’s
These were actually easy to set and get correct. By default Wordpress set the tag and category base urls to be as follows:
Tag Base: http://www.domain.com/tag/
Category Base: http://www.domain.com/category/
Well as I mentioned before this wasn’t going to work for me. Not because it didn’t actually work but more due to my OCD for wanting to get things correct, at least correct in my mind. So in the administration panel under Settings -> Permalinks there are two input boxes to specify the URL structure to use for the tag and category base’s. I set my tag base to be “/blog/tag” and my category base to be “/blog/category”. This left me with the following URLs when saved:
Tag Base: http://www.domain.com/blog/tag/
Category Base: http://www.domain.com/blog/category/
This was perfect and working out well. The only thing left to do was get the permalink structure setup correctly so my blog posts also showed up under “/blog/”. Little did I know that this was going to be a 4 day process of trial and error while doing a lot of searching on Google for answers.
Permalinks
Wordpress Permalinks, my new arch nemesis! Permalinks is the name for the concept of giving a blog post a pretty URL to use rather then a ugly one. Here is an example:
Pretty: http://www.domain.com/general/my-general-post-about-wordpress
Ugly: http://www.domain.com/index.php?id=346
The general idea is that your going to give your blog posts not only a nice looking url that’s easier to remember but also that your getting a little search engine optimization in there by having the title of the post be in the url, hopefully with some keywords. In general the most commonly used permalink structure for Wordpress is “/%category%/%postname%/” which ends up looking exactly like the “Pretty” example I gave above. With that in mind we know that this wont work for me because I wanted everything to be located under “/blog/” that was part of the blog. By now you have the same idea I had.. so lets go through it.
Permalinks are setup on the Settings -> Permalinks page by choosing the “Custom Structure” option and typing in a Permalink structure that fits your needs. So like you guessed, I put in “/blog/%category%/%postname%”. After all I will get extra bonus keywords in my URL’s if the category names also include keywords. This would have made the blog posts links look like this:
Post URL: http://www.domain.com/blog/general/general-post-about-wordpress
This is perfect! Unfortunately it broke my Wordpress. Upon doing this and testing I found that all the post links were working properly however the pagination, page navigation, on the post page, home page, didn’t work. In fact the pagination resulted in a 404 error on some pages and it redirected using a 302 redirect to posts on other pages. Lets sidebar to pagination real quick!
Pagination is the idea of having multiple pages to display the lists of the blog posts. This is simply done by specifying a number of posts per page on the Settings -> Reading administration page. Once you specify a number of posts per page, Wordpress will automatically break up your main posts page, or home page, into multiple pages displaying X number of posts. X of course being what you specified in the option. Pagination URL’s typically look like this:
http://www.domain.com/blog/page/2 or
http://www.domain.com/blog/page/3
So back to permalinks! Once I used the permalink structure mentioned above the pagination on the blog quit working. In fact one page, /blog/page/2, ended up redirecting to a post from last year and /blog/page/3 resulted in a 404 page not found being displayed. Why you ask? All because of those damn permalinks!
After many days of trying to figure out what was causing the issue I ended up changing the permalink structure to see if it was the problem and sure enough it was. So I did many hours of searching for every combination of keywords I could think of to try and solve the issue. I had no luck at all. Turns out the answer was in the codex documentation page for permalinks the whole time.
Upon reading the page VERY carefully many times I can across a paragraph that mentions another issue with permalinks. As it turns out the Wordpress developers suggest that your permalinks structure start with a field that contains a number rather then one that contains text. On the codex page there was a link that goes to a Wordpress testers discussion that explains why.
Basically what it comes down to is that Wordpress has to parse the request for a page against a number of variables. In the testers discussion it mentions that for this reason you should use a number field rather then a text field to start your permalinks structure. This is because all pages always start with a text field and by using a number field you are telling Wordpress that this is indeed a post rather then a page. This helps cut down on processing time to figure out what the user is trying to load and also reduces the number of internal rewrites that Wordpress has to maintain due to the %category% being the first variable of the permalink structure.
This make sense because the same thing did not happen with the tag base or category base. This is because the keywords “tag” and “category” were hard coded into the base’s (in the options by specified above) and therefore Wordpress did not have to guess what the users of those requests were looking for.
Once I changed the permalinks structure to one that has a number for the first field rather then text, the pagination no longer resulted in a 404 and the mysterious redirects were gone. The structure I used was “/blog/%year%/%monthnum%/%postname%” so my URLs were still under “/blog” and they also fell in line with the Wordpress calendar function which year, month and day in it’s url structure.
In the end the options I mentioned above ended up giving me the URL’s of:
Static FrontPage: http://www.weberz.com
Blog Home Page: http://www.weberz.com/blog
Blog Category Page: http://www.weberz.com/blog/category/general
Blog Tags Page: http://www.weberz.com/blog/tag/wordpress
Post Page: http://www.weberz.com/blog/2009/06/wordpress-cms-blog
Now I have a fully working Wordpress CMS system with a blog in a single installation. All of the pages use the same set of template files and plugins for easy administration and everything is working fairly smooth. With any kind of luck at all.. This article helped you setup your Wordpress installation as a CMS and hopefully it didn’t take you 4 days to find it!
Post Tagged With: Wordpress















Posted: June 7th, 2009 at 10:27 pm
You aren’t alone, not having all of my blog’s contents under /blog really bugged me too. This is just what I needed, thanks!
Posted: June 13th, 2009 at 7:29 pm
I did spend 4 days trying to figure this out! Just happy that I found this article before spending 4 more… thanks a million.
Posted: June 30th, 2009 at 3:06 am
At last i found some solution. Thanks
Posted: June 30th, 2009 at 3:08 pm
Great post – I’ve been setting /blog as the blog post directory but hadn’t thought to set the tag, category, & permalinks as you did – thanks for the help.
Posted: July 21st, 2009 at 5:24 am
hey, nice post! I wanted my permalinks set like yours. I also have my blog in a blog/ folder but pagination is broken. It goes to [root]/blog/page/2/ where as [root]/page/2/ is working.
Any ideas how to fix this so pagination works with the /blog/ folder in the url?
Posted: July 21st, 2009 at 7:45 am
Yeah.. The answer is to have a number be the first variable field of your permalink structure. I wanted mine to be /blog/%category%/%post_name% but that doesn’t work. I had to change it to be /blog/%year%/%month%/%day%/%post-name%. However that makes the urls much longer then someone may wish.
You just have to make sure that the first variable in the permalink structure is a number and not text.