August 14th, 2006

Advanced Customization of WordPress Permalink Structure

Part of the Using WordPress as CMS SeriesIf you followed the previous entry in the Using WordPress (WP) as a CMS series, you would already be able to get this sort of sexy permalink structure:

  • Custom Front Page at: http://yoursite.com/
  • Normal Blog Index at: http://yoursite.com/blog/
  • Blog Entries at: http://yoursite.com/blog/post-title/
  • Blog Categories at: http://yoursite.com/blog/category/category-title/
  • Blog Monthly Archives: http://yoursite.com/blog/2006/08/

But this isn’t complete. Let’s now branch into the permalink structure of WP’s pages system. Assume that you want an Articles section – independent of the reverse chronological nature of your blog section, as well as its permalink structure.

Here’s how you would manage these Articles in your Manage >> Pages tab in WP’s admin interface:

WordPress Manage Pages

And this is how their permalinks would (automatically) look like:

  • Articles Index at: http://yoursite.com/articles/
  • Main Topics at: http://yoursite.com/articles/introduction-to-economics/
  • Entries in Topics at: http://yoursite.com/articles/introduction-to-economics/what-is-economics/

Nice, no? You now have a Custom Front Page, a reverse chronological Blog, and a hierarchical Articles section – all bonded together with a clean permalink structure. If you like, you can even add multiple hierarchical sections for FAQs and the like by making more sets of Pages with the same structure as above. So, even at this stage, WordPress has pretty much become a more conventional web site CMS. 

But what if you wanted another date-ordered section for your News (in addition to your Blog)? You would have to use WP’s posts system again. So, how would you ensure that your permalink structure remains as nice as seen above after adding your News? Logically, this is what you would want your end product to be:

  • News Index at: http://yoursite.com/news/
  • News Categories at: http://yoursite.com/news/category/category-title/
  • News Entries at: http://yoursite.com/news/news-title/

Well, I could only think of one easy and non-messy way to get things done, and even then, it doesn’t do everything we want. It involves changing the permalink structure of your posts in the Options >> Permalinks tab to exploit the /%category%/ tag.

Firstly, you should change your permalink structure to: /%category%/%postname%/. Then, you have to create two new categories, Blog and News (you can add more categories if you need more date-ordered sections), and make sure that they have the lowest category IDs. This is because the /%category%/ tag in your post permalink structure will always select the category with the lowest ID if you have multiple categories assigned to a post.

Then, all you need to do is to select one of these categories (either News or Blog) for all the posts you make, and their permalinks will automatically have /blog/ or /news/ pre-pended.

Note: You might also want to remove these two News and Blog categories from all your category listings as they aren’t “normal” categories. Use the exclude parameter in your wp_list_cats() function (or its equivalent in the list_cats() function) to do that.

That’s about it. But I’m sure you’ve noticed that I haven’t touched on how the permalinks of both the category and dated archives are going to work out. I’m sad to say I’ve not found a way to get archives running under both /blog/ and /news/ without messing with rewrite rules. You can only choose one, which is the directory that you selected for your normal blog index under the Filosofo Home Page Control plugin (as described earlier). And even if you mess with rewrite rules, WP just wasn’t meant to run multiple sets of archives. So, you can never have two sets of dated archives for both your Blog and News sections, even if you could simulate multiple category trees by using sub-categories and rewrite rules.

So, now that we’ve run through some of the more critical fundamentals, we can now progress to the “meat” of the Using WordPress as a CMS series. Stay tuned.

P.S.: If there’s demand, I’ll try to put up an “Even More Advanced Guide” utilizing mod_rewrite and .htaccess rewrite rules to simulate multiple category trees as described above. No guarantees though.

Edit: Aiks, forgot that WP2 stores its rewrite rules internally. So, .htaccess files do not even come into the picture.

If you found this post useful, keep updated with future posts by subscribing to blogHelper (for free) through RSS or email.

Remember to share this post as well (if you liked it, of course): These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • digg
  • Fark
  • Furl
  • Ma.gnolia
  • NewsVine
  • Reddit
  • YahooMyWeb

60 Comments

Leave a Reply