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
Installation
- Download top_level_cats.zip, unzip it and save the top_level_cats.php file in your wp-content/plugins directory.
- Activate the plugin through your WordPress admin area (See the official documentation if you need more help with this.)
- Go to Options -> Permalinks in your options panel and press Update Permalink Structure.
- 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
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.
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!
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) ?
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.
It doesn’t work for me. I get a 404 error. :(
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?
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!
@Fil : My Base category was indeed empty. I tried again, and obtained the same error : when I change page, 404 :)
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.
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.
Hmm, I already updated the permalink structure. And I still get a 404.
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?
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.
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.
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)
Rod — Could you try one last thing? Switch your theme to one of the default ones. Do you still have the issue?
I have tested …
Hemingway theme, non customized > same error
I have updated to php5 + Wordpress 2.1.2 > same error
Good luck ! :)
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%/ ?
what did you do my categories? its now working! when i deactivated, my category still doesnt appear. what must i do?
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.
Easy installation and works fine, thanks a lot! (I use it on www.isi-blog.de)
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?
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!
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
Same Problem as Rod and Steve.
404 when using /%category%/%postname%/
You’re the king, when you can fix that.
Ziggy
Another problem: Subcategory.
Post under subcategory works, but subcategory page (example.com/cat/subcat/) gives a 404.
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 !
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.
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
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
oops
structure should be:
/%category%/%postname%.html
Noel
Thanks a lot for the plugin!
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?
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.
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!
Ok, I discovered that this is NOT a plugin issue. TY
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?
9 Trackbacks/Pingbacks
[…] 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. […]
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! …
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…
[…] 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 […]
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í…
[…] benutze das Top Level Categories Plugin von Filipe Fortes zusammen mit einer Permalink-Struktur der Form /%category%/%postname%, wie man […]
[…] Det kan downloades her: top-level-categories-plugin […]
[…] 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 […]
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…