Support » Requests and Feedback » permalink by category

  • I’ve been trying to figure out how to seperate individual categories into their own pages with no luck. Rather, I succeeded in seperating categories into their own pages (through the use of some nasty hacks) but, I can’t get the WP generated permalinks to link to those pages. Let me illustrate.
    My clients site has two categories that I want seperated; news and articles. I can create a news.php page to show a listing of only the news items, and an articles.php to show a listing of only the article items, but clicking on a permalink to see the whole news item or the whole article takes you to index.php to display the post, not to its respective category page. OK, it might not seem like a big deal but it is. Because of this behaviour, I cannot style my individual news pages and my individual articles pages differently.
    Very annoying since the design incorporates different header graphics for news, and differernt header graphics for articles.
    The problem seems to lie in how WordPress generates its permalinks. In MT you could choose how you wanted to archive you entries, by date or by category. In WP, permalinks are only generated by date, so it’s impossible to link to an individual post through its category. Ideally, lets say the permalink of a news item called My Cheese Sandwich was in the form of :
    A simple mod rewrite would allow the post to be displayed through news.php and not through index.php. This would definately make WP a lot better and very robust, since it would be possible to truly seperate categories.
    So what I’m requesting is for a way to change the permalink behavior so that you can choose how you want your archives displayed; by date, or by category. This may be a problem since each post can have multiple categories. A way around this would be to specify the default category for each individual post. So that if one of my posts is in the news, personal, and tech categories, i can choose a default of news so that the post’s permalink will be generated with that category.
    Any other thoughts?

Viewing 12 replies - 1 through 12 (of 12 total)
  • i’ve been looking more into how to implement this and i found something very encouraging.
    there seems to be a depreciated variable called $post->post_category that was in use before v1.2.
    This is actually perfect for the purposes of implementing a category permalink option. The default category (chosen on a post by post basis) can be stored here and in the post2cat table (to be able to display multiple categories).
    I looked at the code that generates the permalinks but it is too complicated for my feeble php skills. Anyone out there want to take a crack at it?

    Moderator Ryan Boren


    WordPress Dev

    I’m working on this right now. It should be done soon. If a post has multiple categories, you can query it via any of the categories. Here’s an example with a permalink structure of /archives/%category%/%postname%/.
    If the post has a sub-category…
    Any of these will take you to my-post. When creating the permalink, however, we must pick only one category. Right now, the first category in the post’s category list is picked.
    Generating rewrite rules that direct each category to separate index pages is another matter. That is not going to happen by default in WordPress. You’ll either have to hand edit your rewrite rules or make index.php handle all of the different categories. index.php can be coded to output a different style for each category.

    Great… I can’t wait for this. My thinking all along was to use rewrite rules to redirect specific categories to their own index. That way i can have a seperate news index and a seperate articles index.
    I think it would be better tho to be able to choose the default category rather than have the first one in the list used. While it suits me just fine (because each post for my purposes will have only one category), it would be more dynamic to be able to access the posts from other categories if they apply.
    Like I said in my previous post, there is a depreciated variable that keeps the category ID for each post. This could possibly be used to hold the default value and to generate the permalink. So when you are creating your entry and you press Publish, the categories would be written to the post2cat table and the category_id field in the posts table. It database would store the information twice as a result, but I think it’s the easiest way without resorting to UNION queries and the like.
    Keep us posted on your progress. If this works, it will definately make WordPress a heck of a lot better.

    Lemme clarify my previous post… Here’s what i meant to say.
    So when you are creating you entry and you press Publish, the categories would be written as normal to the post2cat table and the DEFAULT category ID would be written to the category_id field in the posts table…

    This is looking great! I’ve been waiting for this functionality for a long time… will this be part of WP or a plugin?
    also, instead of /archives/category-one/my-post can it just be
    /category-one/my-post – I see no reason to place archives in the structure.

    Just tried it out with the new nightly and it works great! I can now have different indexes for specific categories that i choose. I’ll write more about this later.

    Is it possible to have a different template for a category, and then another different one for a subcat?

    I’m trying to do very much the same thing, except I only want the titles (and perhaps an excerpt) of the posts in each category displayed, rather than the entire contents of each category. Is there a way to accomplish this?


    Hi, can you illustrate on how you do it? Im not sure of how. thanks

    Hello…. is this done? Is there some way we can use category references in permalinks instead of %year%, %monthnum%, %day% etc…

    I want to have category hierarchy in the parmalink of a post… I think this must be possible through some plugin… is there one already developed ?

    please permit me one naïve question? Would it not be simpler to create a series of blogs, and post to one or multiple blogs much as the checkboxes for categories. you could use a mailing list or whatever, like I said, I’m a newbie.
    switch between blogs via sidebar?.
    another twist would be that you could easily have separate collections of header images, nice if you use a random image header. Then you could make the images fit the topic.
    of course, then a search within the blog wouldn’t yield hits in the other blogs that you have. or could you solve that by using the Google instead of the Word press?
    even more of course, the is not one question anymore. oops…

    even more oops, I just realized that it is probably only simpler if you have the one click installation and I do, at

    Moderator James Huff


    Yes, you could install a separate blog for each topic, but tying them together would be very difficult and would require a lot of core code hacking.

    On the other hand, this is a very old thread and most its information is now out of date. Since the release of v1.5, category hierarchy has been an option for permalinks. Also, if you search through these forums, you will see that it is possible to have a new theme (or header image) for each category. And, each category can have its own RSS feed (search the forums for that info too), so you can effectively create the illusion that one blog with many categories is actually several separate blogs.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘permalink by category’ is closed to new replies.