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

32 Comments

  • 1

    […] Advanced Customization of WordPress Permalink Structure […]

  • 2

    Thanx , that`s what i was looking for ,
    i was working at something Like that at
    First aid Guide
    but i stopped this project weeks ago , now i`ll use ur way :D
    thanx again

  • 3

    It`s Hamza
    freewaydesign.com

    am making First aid Guide
    http://firstaid.medpeek.com/
    but How i can list the page at the home page like u did
    http://a-level.econoref.net/articles/

    i used

    then exclude but not with the child pages.

    and many thanx

  • 4

    […] Contact Advanced Customization of WordPress Permalink Structure […]

  • 5

    […] Bloghelper continues the WordPress-CMS series with Advanced Customization of WordPress Permalink Structure. […]

  • 6

    […] Mass Edit PagesSimple, but truly effective. This plugin allows you to the page parents and menu orders of multiple pages all in one interface. I’m sure this will come in handy for those using WP’s pages system extensively (i.e. those using WP more as a CMS), and is a great fit for the CMS-friendly concept or rather, permalink structure, I outlined yesterday. […]

  • 7

    What I want in a permalink structure is to do away with the preset “title” in the link.

    Instead of

    example.com/category/named-category/post-title-here

    I want

    example.com/named-category/post-title-here

    I can’t figure out how to get that. Suggestions?

  • 8

    If you don’t want that /category/ in there…just don’t use it.

    Seriously.

    See here:

    http://macstansbury.com/podcasts/

    And here:

    http://macstansbury.com/category/podcasts/

    I’m not sure how to get rid of the category, it seems to be in there purposefully permanently, but it doesn’t hurt anything if you leave it out. I’ve found you can do a lot of neat tricks with the WP permalink structure.

  • 9

    MacStansbury: Sorry, but your site is spewing 403 errors at me. :) And I don’t really understand what you mean by “don’t use it” because from what I know, WordPress forces you to use a base prefix for your categories. Or am I missing something (as usual…)?

    Lorelle: Aiks, that’s a real toughie, which I’m afraid doesn’t seem to have a solution since permalinks would clash if there was a Page with post slug “named-category”.

    This clashing carries over even when you try a workaround by setting your category permalinks to match your blog entries’ permalinks, e.g. if your blog permalink structure was “/blog/%postname%/”, setting your category base to “/blog” would kill all your rewrite rules. You’d get categories at “example.com/blog/named-category/” but your posts at “example.com/blog/post-title-here/” would return you a 404 error.

    So, it seems to me that there isn’t a documented way to do what you want yet. In fact, I might have been too optimistic to say that I could put up an Even More Advanced Guide. Aiks. I’ll keep trying first though since adding additional rewrite rules might work if they don’t clash.

    Author Comment
  • 10

    Odd that it’s giving you that. I tried to get me some of them 403s, and was unsuccessful with two different computers. How I thought I had it running was that you could click either of those links and get the same thing. It comes from how I set the permalink structure on the whole site:

    /%category%/%postname%.htm

    The trick is, I’ve used my category exactly like that, as to give me some faux directories. So my category for News would be:

    my.tld/news/

    with a post titled “Story”

    my.tld/news/story.htm

    By default, WordPress will stick a /category/ in front of any category listing. You can choose to add something else to that in the “Category base.” My hack/trick/non-working hack is to trick WordPress into doing what I said to do. If it’s not working, I guess I need to unscrewupify the thing, but it seemed to work before.

  • 11

    Amazing. You’re absolutely right. It’s one weird workaround allright. But Lorelle’s problem still remains though since the desired permalink structure for the site would be just /%postname/.

    I’m also afraid that I can’t comprehend this phrase: “as to give me some faux directories.” Nevertheless, cool discovery. :)

    P.S.: Aiks, maybe it’s just my connection, but your site is still spewing 403s.

    Author Comment
  • 12

    On second thought, this workaround would be rather irritating since wp_list_cats would still show the /category/ prefix. Darn.

    Author Comment
  • 13

    So the bunker breaker on the category part of the permalink really is a conflict with Pages? You would think that a simple check to see if a Page title or slug matches a Category and respond with “already in use - pick another title” would be enough to stop such a conflict.

    But then I tend to think in simple methods. ;-)

    With my static site, I loved having posts under the names of their categories, grouped together so people would know they were viewing posts in the wordpress category or photography category or whatever. Now, they are in the category/wordpress category and category/photography category - horribly redundant.

    Hmmm, but what if it was set to be wordpress-category/post-title-here or photography-category/post-title-here? Would there be a rewrite for adding the category name with a hyphen to the word “category” that would avoid the conflict?

    Shooting at the moon! ;-)

  • 14

    In practical terms, the conflict with pages should be why WP forces a prefix for your categories. Code-wise, it’s probably due to what Alex King described here (though his hack to solve the problem doesn’t seem to work for me).

    Hehe, I would think that that simple check would need some extensive modification to the current titling system. :)

    Hmm, I’m not sure if I’m reading you right, so let me confirm this. You want your blog posts to come under “/category-title/post-title” ?

    If so, MacStansbury’s workaround (as described above) can surprisingly get that done right. Although your categories will still have a /category/ prefix by default, you’ll find that even if you remove that prefix, the category appears correctly. Weird, but useful. You’ll probably have to test it out yourself to believe it.

    Author Comment
  • 15

    […] Now that we’re done with a large portion of the technical basics of Using WordPress (WP) as a CMS, let’s continue on with the next step: Using WP for a portfolio site (primarily graphics and design-based). […]

  • 16

    […] (Relatively) Rigid Permalink StructureChanging your permalink structure in WP normally involves only the general URL structure of your posts, e.g. whether it’s /year/month/date/ or just /postname/, and changing the prefix of your categories. So far, there’s no way to change the permalink structure of a single post or page, or set your categories to run without any prefix! You might have noticed that categories can’t go under yourblog.com/category-name/ because it could conflict with a page under yourblog.com/page-name/. There is a hackish way (see comments unde post) of doing it, but it’s not dependable - and should be used as an indicator of WP’s rigid permalink structure. […]

  • 17

    […] Optional Introductory Reading: We’ll be playing around a bit with your permalink structure. Nothing special, but you might want to read an introductory article I wrote on this just in case. […]

  • 18

    “If so, MacStansbury’s workaround (as described above) can surprisingly get that done right. Although your categories will still have a /category/ prefix by default, you’ll find that even if you remove that prefix, the category appears correctly. Weird, but useful. You’ll probably have to test it out yourself to believe it.”

    Right, I tested this trick, it works for the FIRST PAGE of the category archive. The paging from that page on does not work.

    ie:

    http://www.myblog.com/bunnies/

  • 19

    Oops, sorry, my mistake. You’re right, paging breaks if you’re using clean URLs. But if you use WP’s default permalinks, i.e. http://myblog.com/bunnies/?paged=2, it seems to work. Here’s a real-life example: http://articles.zmang.com/web-design/?paged=2.

    So, it’s probably because WP lacks rewrite rules for myblog.com/bunnies - which might possibly be added manually if you really want to explore this avenue.

    Sorry again for the misunderstanding I caused.

    Author Comment
  • 20

    Is there a way to shorten ‘post title’ or ‘page title’ in the permalink? I mean, if for example, you are using the /%category%/%postname%/ structure and the post name is too long, is there a way to truncate it at the third word or something? I am kinda new to customizing WP. Thanks!

  • 21

    […] Una Struttura di Permalink (Relativamente) Rigida Quando in WP si cambia la struttura dei permalink, in genere vengono modificati gli indirizzi degli articoli e i prefissi delle categorie. Non c’è la possibilità di cambiare in maniera semplice la struttura dei permalink di una singola pagina o di un singolo articolo, oppure configurare alcune categorie senza nessun prefisso senza rischiare un conflitto con gli articoli. Un sistema c’è (vedi i commenti all’articolo), ma non è molto consigliabile e necessita una discreta conoscenza del funzionamento di wp_rewrite. […]

  • 22

    […] WP ha una Struttura di Permalink (relativamente) Rigida Quando in WP si cambia la struttura dei permalink, in genere vengono modificati gli indirizzi degli articoli e i prefissi delle categorie. Non c’è la possibilità di cambiare in maniera semplice la struttura dei permalink di una singola pagina o di un singolo articolo, oppure configurare alcune categorie senza nessun prefisso senza rischiare un conflitto con gli articoli. Un sistema c’è (vedi i commenti all’articolo), ma non è molto consigliabile e necessita una discreta conoscenza del funzionamento di wp_rewrite. […]

  • 23

    […] Nota: Questo articolo è la traduzione in italiano di Advanced Customization of WordPress Permalink Structure il quinto di una serie di post pubblicati su blogHelper che spiega come trasformare WordPress in un sistema di gestione di contenuti. La traduzione viene pubblicata qui con il permesso dell’autore: Ang Zhuu Ming. […]

  • 24

    Hi! Thanks for interesting post!

    I have notice about your phrase “make sure that they have the lowest category IDs”. I’m using my custom plugin which allows to select category which will be used for permalink generation. And today I found your post and decided to publish it: http://kpumuk.info/projects/wordpress/wordpress-plugins-scategory-permalink-select-category-for-permalink-generation/

    Hope, it will help somebody

  • 25

    Best troubleing of cialis works relieve pill done on cialis cialis should machine websites that smells dwarf blurred vision. Sexual ring discharges a method to produce seminar to bitterness in absence.

  • 26

    So cool site, http://www.sexworm.info/dating.htm

  • 27

    Thanks for the info. I don’t know why wordpress don’t make this the default.

  • 28

    […] inspect this elevated synopsis at http://bloghelper.is-there.net/advanced-customization-of-wordpress-permalink-structure/ about […]

  • 29

    […] שמות קצרים כשמדובר בלינקים. להלן מקורות למאמרים בנושא: פרמנלינקים, התצורה הנכונה, וורדפרס פרמנלינקים. וכמה כתבות מהאתר […]

  • 30

    There’s nothing I hate more than a list of 7 things on 7 seperate pages

  • 31

    @health.. lol.. it’s not only you.. me too..

    This is one of the good of Wordpress.. manipulating permalink is easy and help for SEO

  • 32

    sasd

Leave a Reply