Skip past navigation, straight to the content

Top Level Categories Plugin 0.1

Introduction

The Top Level Categories plugin allows you to remove the prefix before the URL to your category page. For example, instead of fortes.com/category/work, I use fortes.com/work for the address my “work” category. WordPress doesn’t allow you to have a blank prefix for categories (they insert category/ before the name), this plugin works around that restriction.

Download

Top Level Categories v0.1

Installation

  1. Download top_level_cats.zip, unzip it and save the top_level_cats.php file in your wp-content/plugins directory.
  2. Activate the plugin through your WordPress admin area (See the official documentation if you need more help with this.)
  3. Go to Options -> Permalinks in your options panel and press Update Permalink Structure.
  4. That’s it! Your category links are now changed!

Donate

If you’re feeling generous, go for it:

Notes

I use this plugin in conjunction with the excellent Permalink Redirect Plugin. If you’re using the plugin, you should make sure to fix a simple bug in the program that messes up category feeds. You can do so by adding the following code to the file on line 174 (right before the return $link; line):

        if (is_feed()) {
        	$link = trailingslashit($link) . "feed/";
        }

Known Issues

This plugin will not work if you are using a permalink structure that is only the post name (i.e. /%postname%/ in the options). This is because it creates an ambiguous situation where both categories and individual posts end up with the same URLs. To fix this (if you don’t mind switching your post URLs), switch permalink structure to one of the built-in settings (like Date and Name Based).

37 Comments

  1. wordks perfectly … BUT :)

    when you want to go in previous entries (inside a category .. example (I have desactivated the plugin : http://www.le-hiboo.com/categoy/cinema … which becomes with your plugin http://www.le-hiboo.com/cinema/) /page/2/ … = 404 error … > all cats have the same fate when the plugin is activated.

    Posted Feb 28, 2007 at 6:44am | Permalink
  2. Excellent plugin! I’ve been trying various forms of hackery to get this to work for a while, but wasn’t terribly thrilled with anything I’d come up with. I’m especially glad it works with the FuCoder Permalink Redirect plugin. Thanks!

    Posted Feb 28, 2007 at 8:05am | Permalink
  3. Rod: That’s a strange problem, since it works fine on my blog and all the others I’ve tested. I must have missed something.

    Could you try this for me? On your options page, make sure the category base is empty (which will reset it to the default, “category/”) — are you still seeing the issue?

    Also — do your feeds work when you have the plugin enabled (aka /category/feed) ?

    Posted Feb 28, 2007 at 8:50am | Permalink
  4. DNM

    Does not work for me. :(
    I tried it at three different blogs. One of them had no other plugins activated. If clicking at domain.tld/blog/name-of-category/ I get a 404 error.

    Posted Mar 1, 2007 at 12:58am | Permalink
  5. amelia

    It doesn’t work for me. I get a 404 error. :(

    Posted Mar 1, 2007 at 1:24am | Permalink
  6. amelia

    I have deinstalled the plugin and now I get 404 errors while I try to access to my old categorys. It has broken my blog. How can I overcome this?

    Posted Mar 1, 2007 at 1:58am | Permalink
  7. I got a 404 error when viewing category pages until I went to my Permalink Options page, without clicking the Update button the problem was resolved. Strange, but it works now so thanks for this plugin!

    Posted Mar 1, 2007 at 4:46am | Permalink
  8. @Fil : My Base category was indeed empty. I tried again, and obtained the same error : when I change page, 404 :)

    Posted Mar 1, 2007 at 5:05am | Permalink
  9. Much thanks for this Filipe.

    Allows me to take another core edit off my list, and saved me from having to write my own. Works like a champ on my couple of setups, paged navigation and all.

    Posted Mar 1, 2007 at 8:32am | Permalink
  10. All: I’ve added another step to the instructions — make sure you update the permalink structure in your blog in order to give the plugin a chance to change the rewrite rules.

    Let me know if you’ve done this and it still doesn’t work.

    If you do uninstall the plugin, you must go back and update the permalink structure with the plugin deactivated in order to reset your rewrite rules. Hopefully, I can make all this automatic in the next version.

    Posted Mar 1, 2007 at 8:34am | Permalink
  11. DNM

    Hmm, I already updated the permalink structure. And I still get a 404.

    Posted Mar 1, 2007 at 10:47am | Permalink
  12. DNM: Sorry, but I have no idea what’s wrong. It’s worked on every blog I’ve tested it on. You might have to live without the plugin.

    If tell me a few things, I can try to replicate the issue.

    • What version of WordPress are you running?
    • What type of post permalinks are you using?
    • What was your old category permalink?
    Posted Mar 1, 2007 at 11:09am | Permalink
  13. DNM

    What version of WordPress are you running?
    2.1.1

    What type of post permalinks are you using?

    /%postname%/

    What was your old category permalink?

    http://domain.tld/blog/category/plugins/

    I hope that helps. If not, tell me and I will send you an email.

    Posted Mar 2, 2007 at 1:22am | Permalink
  14. DNM: Ah! That helps. I tested it out, and the plugin won’t work if you are just using /%postname%/ as your permalink structure.

    The reason is that there’s no good way for WordPress (or my plugin) to tell the difference between a post named “plugins” and the category named “plugins”. In this case, WP tries the post first, and gives up when it doesn’t find it. I don’t know any way around this right now, but I’ll think about it.

    Posted Mar 2, 2007 at 9:21am | Permalink
  15. I drop it.

    1. Activate the plugin
    2. Options > Permalinks > Update
    3. Go on my site …
    4. http://www.le-hiboo.com/cinema/ > OK (instead of http://www.le-hiboo.com/category/cinema/)
    5. http://www.le-hiboo.com/cinema/page/2/ = 404

    It’s the life. What a pity. (I use Wordpress 2.0.4)

    Posted Mar 2, 2007 at 3:50pm | Permalink
  16. Rod — Could you try one last thing? Switch your theme to one of the default ones. Do you still have the issue?

    Posted Mar 2, 2007 at 4:05pm | Permalink
  17. I have tested …
    Hemingway theme, non customized > same error
    I have updated to php5 + Wordpress 2.1.2 > same error

    Good luck ! :)

    Posted Mar 4, 2007 at 11:07pm | Permalink
  18. Steve

    This thing is *almost* perfect. I tried to use the commonly preferred /%category%/%postname%/ format and ran into the same page/2/ 404 problem. Using any other permalink format fixed it, even a custom one, such as /%category%/%year%/%postname%/

    If you can ever figure this one little gotcha out, it’ll be a hall of fame plugin :) Did the blogs you tested use /%category%/%postname%/ ?

    Posted Mar 9, 2007 at 10:22pm | Permalink
  19. bddoom

    what did you do my categories? its now working! when i deactivated, my category still doesnt appear. what must i do?

    Posted Mar 10, 2007 at 3:01am | Permalink
  20. bddoom — Try updating your permalink structure (this causes WP to re-do all the rewrite rules).

    Steve — Being in the hall of fame would be nice. I’ll see if I can make that fix for the next version.

    Posted Mar 10, 2007 at 3:43pm | Permalink
  21. Easy installation and works fine, thanks a lot! (I use it on www.isi-blog.de)

    Posted Mar 14, 2007 at 1:56pm | Permalink
  22. Andreas

    It works fine for me, but it ruins the AJAX-Search that comes with the K2 theme (getk2.com), which I would really like to use. As soon as I have activated the plugin and updated the permalink structure, the K2 live search returns no results. Is there a workaround?

    Posted Mar 18, 2007 at 6:31am | Permalink
  23. Hi, I tried your plugin, but it doesn’t work. Using 2.12, and this permalink “extension” plugin.

    http://kpumuk.info/projects/wordpress/wordpress-plugins-scategory-permalink-select-category-for-permalink-generation/#comment-29925

    Any idea what might cause this?

    Thanks!

    Posted Mar 20, 2007 at 10:26pm | Permalink
  24. I’m on K2 v.95 (getk2.com). When I’ve got this plugin activated, the advanced navigation (ajax older/newer nav) has issues.

    When using the advanced navigation on a category archive, it works fine. However, if you use the advanced navigation on the normal “blog” page, hitting older brings up a “not found” 404 page.

    Any ideas?

    Thanks,
    Karen

    Posted Mar 20, 2007 at 11:58pm | Permalink
  25. Ziggy

    Same Problem as Rod and Steve.
    404 when using /%category%/%postname%/

    You’re the king, when you can fix that.

    Ziggy

    Posted Mar 28, 2007 at 2:06am | Permalink
  26. Another problem: Subcategory.

    Post under subcategory works, but subcategory page (example.com/cat/subcat/) gives a 404.

    Posted Apr 6, 2007 at 8:32am | Permalink
  27. Same Problem as Rod and Steve.
    404 when using /%category%/%postname%/

    You’re the king, when you can fix that.

    Same for me too.
    If you have an idea … ;)

    Great plugin also !

    Posted Apr 9, 2007 at 3:00am | Permalink
  28. Same here, subcategories don’t work. They’s be essential for me… If you use the category base ./ hack, they don’t either, so this seems to be a problem beyond simple fixing.

    Posted Apr 15, 2007 at 12:16pm | Permalink
  29. Ok, I’ve done a little bit of debugging (~3 hrs) and found out, why these problems exist. Wordpress uses a number of regular expressions for URL parsing. In my case, I had a permalink structure of /%category/%postname%/. This resulted in Wordpress running into the post permalink structure first, category second. If it were the other way round, it wouldn’t be any different. There is simply no way do decide if an URL belongs to a post or a category.

    Skipping the trailing slash didn’t help either, because WP trims it off by default.

    The only workaround solution I found was to make my permalink structure /%categoryname/%postname%.html I do think, this is one retarded concept, but since nobody wrote something better… Use the workaround and be happy. :P

    Posted Apr 15, 2007 at 11:16pm | Permalink
  30. You’rr the king!

    using the custom category /%categoryname/%postname%.html
    works perfectly with categories, subcategories and single posts.
    Without the html on the end it doesn’t work for subcategories

    Please put that in your documentation so that others know!

    thanks again

    Noel

    Posted Apr 24, 2007 at 8:20am | Permalink
  31. oops
    structure should be:
    /%category%/%postname%.html

    Noel

    Posted Apr 24, 2007 at 8:27am | Permalink
  32. Jonathon

    Thanks a lot for the plugin!

    Posted Apr 25, 2007 at 11:47am | Permalink
  33. Thank you, the idea is great and simple, but unfortunately it doesn’t work with subcategories, as it said before.
    Any ideas how to improve it?

    Posted Apr 27, 2007 at 6:36am | Permalink
  34. Awesome, thanks for another fantastic plugin. :) I’ve got it set up on a friend’s blog and it was just what we needed.

    It didn’t work when I left the category base blank, so I changed it to /category and now it’s working perfectly with categories and subcats on WP2.1.3.

    Posted Apr 30, 2007 at 5:02am | Permalink
  35. Great work! It works very well with categories and subcategories but not with the “next” or “previuos” link (aka next_posts_link() and previous_posts_link()). The url generated is something like

    http://mezzomondo.nelblog.it/page/n

    but this always lands on the first page.

    The permalink structure is /%year%/%monthnum%/%day%/%postname%/

    Thank you for your time, anyway!

    Posted May 15, 2007 at 3:05pm | Permalink
  36. Ok, I discovered that this is NOT a plugin issue. TY

    Posted May 16, 2007 at 12:55am | Permalink
  37. Hi there,

    Excellent plugin but I too have run into a few small problems, possibly because I’m using WP v2.2

    It all works fine except for pages, for example:

    http://phobea.com/news/ - works fine, but
    http://phobea.com/news/page/2/ - displays nothing

    Any ideas?

    Posted Jun 10, 2007 at 9:45am | Permalink

9 Trackbacks/Pingbacks

  1. Posted Feb 28, 2007 at 8:25am | Permalink

    […] on my previous solution for manipulating the category URIs in WordPress, but then I came across the Top Level Categories plugin that does exactly what I’ve been trying to accomplish without all of my half-assed hackery. […]

  2. Posted Feb 28, 2007 at 1:28pm | Permalink

    Top Level Categories Wordpress Plugin beseitigt „/category/“-Ballast für Wordpress-Blogger…

    Wordpress wirft dank Top Level Plugin seinen URL-Ballast über Bord. Nach vielen Patches und eigenen Experimenten macht ein Wordpress Plugin den Weg frei für eine saubere und schnelle Lösung. Ausprobieren, Testen, Kommentieren! Endlich! …

  3. Posted Mar 1, 2007 at 10:22am | Permalink

    Wordpress ohne /category/ in der URL, das Top Level Wordpress Plugin…

    Jörg Petermann hatte ja schon vor einiger Zeit einen Workaround beschrieben, wie man diesen lästigen Ballast aus der von Wordpress generierten URL entfernen kann. Nun verweist Jörg auf seinem Blog auf das Top Level Wordpress Plugin von F…

  4. Posted Mar 5, 2007 at 10:26pm | Permalink

    […] Released This forum post identified the problem, and while I have not get around to look at it, Filipe has provided the fix. So there you go — Permalink Redirect 0.6.3, now with category feed URL […]

  5. Posted Mar 26, 2007 at 5:57pm | Permalink

    WordPress Plugin: Top Level Categories…

    Acabo de encontrar un plugin interesante en concepto — aunque bastante verde — para WordPress: Top Level Categories.

    Su función es sencilla: permitir una estructura de permalinks sin el prefijo de “/category/”, si la categorí…

  6. Posted Apr 11, 2007 at 10:52pm | Permalink

    […] benutze das Top Level Categories Plugin von Filipe Fortes zusammen mit einer Permalink-Struktur der Form /%category%/%postname%, wie man […]

  7. Posted May 17, 2007 at 9:05am | Permalink

    […] Det kan downloades her: top-level-categories-plugin […]

  8. Posted Jun 18, 2007 at 5:00am | Permalink

    […] gibt mehrere Hacks um das Ding zu entfernen. Am beste das Top Level Categories Plugin installieren, im Admin-Panel aktivieren, noch einmal in den Bereich Permalink-Struktur gehen und […]

  9. Posted Jun 20, 2007 at 11:53am | Permalink

    Top Level Categories Plugin 1.0…

    There’s a new version of the Top Level Categories plugin. The changes aren’t huge, but they do fix all known issues, including:

    Will now work correctly with the /%category%/%postname% and %postname% permalink structures (this was the top r…