Categories
Package/plugin/module WordPress

Single Category Permalink v1.0

I’d like to announce the first official release of the Single Category Permalink plugin (v1.0) for WordPress.

Modify the %category% permalink structure tag to generate a category-based permalink structure that only displays the lowest category in a hierarchy, as opposed to the entire hierarchy of categories.

The plugin’s official homepage is located at :
coffee2code.com/wp-plugins/single-category-permalink.

This new plugin is part of coffee2code’s 14 Days of Plugins (new plugin #12).

Comments welcome on this post for this version of the plugin. Comments will be closed once this release has been superseded by another.

12 replies on “Single Category Permalink v1.0”

Hi Scott,

Does this change the category archive permalink as well?

Say there’s a category page of:
http://www.a.com/category/first-category/child-category/another-child-category/

Would that change to:
http://www.a.com/category/another-child-category/

If not, is there a plugin that does this?

Preferably, I’d like the category permalink to be:
http://www.a.com/another-child-category/

Please let me know.

Regards,
-Ray

Depends on how you have your permalinks set up. If you have defined a permalink structure that has %category% in it, such as %category%/%postname%, then your preferable example would work, i.e. you would have

http://www.a.com/another-child-category/

If your permalink structure does not contain %category%, and you are looking to just fiddle with the category permalink, which is prepended with /category, this plugin could get you http://www.a.com/category/another-child-category/ but you’ll have to comment out this line in the code:

// $catlink = str_replace('/category/', '/', $catlink);

(The two slashes at the beginning are what you need to add in order to comment out the line. The plugin you have won’t have those slashes.)

I’ll try to make the impending update to this plugin deal with the situation you seem to be suggesting. Let me know if I’ve cleared things up for you and if one of the suggestions work out.

Hi Scott,

Thanks for the quick reply.

My permalink structure right now is:
/%postname%/

I want to keep this permalink structure; would I run into any conflicts using this structure?

I will test out your fix on my localbox and see what happens.

-Ray

The plugin shouldn’t cause any conflicts with your permalink. This merely attempts to make %category% translate just to the lowest-level category instead of the whole category hierarchy. Since you aren’t using %category%, the plugin won’t do anything in that regard.

That said, currently the plugin will strip the “category” base (unless you tried the hack I mentioned above), but would fail to produce a valid link to the category archive (since you didn’t use %category% as the first part of your permalink structure). However, it seems like the Decategorizer plugin might add that handling, so given your situation, you may best benefit from both plugins working together.

I haven’t looked at Decategorizer so I can’t say for certain things will work. But give it a try and let me know how it goes.

Works quite nicely!

I have both your plugin and Decategorizer activated on my testbox and it works well. Even category feeds work nicely!

I guess the only thing I have to think about is redirecting the old category index pages to the new ones before I implement this on our production environment.

I think I’ll use the Redirection plugin to do this.

But, just wanted to say, great plugin!
I’ve been looking for something like this for awhile now!

Hi Scott,

I’ve been experimenting with another “category” base removal plugin.
wordpress.org/extend/plugins/wp-no-category-base/

However, this plugin doesn’t work as well as Decategorizer.

The WP-No-Category-Base plugin seems to take priority before your plugin can handle the category depth.

Not sure if that’s the right logic, but that’s what I think is the problem 😉

from the above comments i expected this would give me the lowest category level of post — so if i have a post that’s in /catname/subcat/subsubcat/, this plugin would allow me to use a permalink with just /subsubcat/.

two questions:
(1) that’s not what’s happening. instead, i’m getting all links rewriting to /subcat/, even if they are also in /subsubcat/.
(2) more importantly (to me), what i _actually_ want to accomplish is to find a way to create a link that contains just /catname/, _not_ the subcat or any of its children. is there an easy way to do this?

thanks! 🙂

Hi lydia, it seems like your understanding of how the plugin should work is correct. I’m assuming you changed your site’s permalink structure to a custom structure using %category%? (Just covering bases.) If so, then it’s likely the plugin may need an update to ensure compatibility with the latest WordPress. While I have been updating my catalog of plugins, I haven’t gotten to this one yet. But it will see an update, so stay tuned.

As for your desired request, are you looking for:
a.) A custom permalink structure, such that when making use of %category%, only the top-level category gets inserted in place of %category%
b.) A special template tag, i.e. top_category_link() which will create a link to the top-most category for a post (not assuming possible multiple top-levels)
c.) Like (b), but you actually care about the permalink structure, i.e. you want site.com/topcat rather than site.com/category/topcat (the latter being WordPress’s default category structure format)?

Leave a Reply

Your email address will not be published.