[wp-hackers] Cruft-free categories in 2.x?

Jefte Puente jp at jefte.net
Tue Mar 21 14:04:32 GMT 2006


>From past experience functional permalinks without /category/ prefixed
depends much on server configuration and version. This is the answer I have
been given repeatedly in the past. Personally, I've given up on this - as Ryan
Borens reduced/alteranative rewrite
rules/plugins<http://boren.nu/archives/2004/10/08/alternative-rewrite-rules/>do
the trick for me.

jefte

On 3/20/06, Stewart Ugelow <stewart at ugelow.com> wrote:
>
> Like many on this list, I decided to take the upgrade plunge to the
> 2.x branch after the latest security updates. In doing so, I've run
> into some of the issues that Alex King describes at
> http://www.alexking.org/blog/2006/03/13/changes-in-wp-20/.
>
> I've found workarounds for most of the issues, but my white whale is
> how to coax the new rewrite rules into not requiring /category before
> all my %category% permalinks. Based on the documentation I've read,
> the following plugin code should do the trick, but doesn't. I'm
> clearly missing some crucial piece of the puzzle. Anyone out there who
> can shed some insight?
>
> function category_rewrite_cleanup() {
>         global $wp_rewrite;
>         global $wp_query;
>
>         //load the rewrite rules
>                 $swap = $wp_rewrite->wp_rewrite_rules();
>
>         //generate the "official" category rules
>                 $cat_perm = $wp_rewrite->get_category_permastruct();
>                 $cat_rules =
> $wp_rewrite->generate_rewrite_rules($cat_perm);
>
>         //remove the official rules from the swap
>                 foreach ($cat_rules as $key=>$value) {
>                         unset($swap[$key]);
>                 }
>
>         //define my rules
>                 $my_rule['(.+?)/?$'] = 'index.php
> ?category_name=$matches[1]';
>
>         //add them to the swap
>                 $swap = array_merge($swap,$my_rule);
>
>         //reset the rules with the swap value
>                 $wp_rewrite->rules = $swap;
>
>         //set the category structure
>                 $wp_rewrite->category_structure = '/%category%';
>
>         //set verbose rules
>                 $wp_rewrite->use_verbose_rules = true;
> }
>
>
> // Hook in.
>      add_filter('init', 'category_rewrite_cleanup');
>
> Many thanks,
> Stewart
>
> --
>
> Stewart Ugelow
> www.ugelow.com
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list