WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/04/2010 10:37:25 AM (9 years ago)
Author:
dd32
Message:

Introduce hierarchical taxonomy URL's, Can be enabled by setting 'hierarchical_url' to true upon taxonomy registration. See #12659

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/taxonomy.php

    r15690 r15705  
    271271
    272272    $defaults = array(  'hierarchical' => false,
     273                        'hierarchical_url' => false,
    273274                        'update_count_callback' => '',
    274275                        'rewrite' => true,
     
    296297            'with_front' => true,
    297298        ));
    298         $wp_rewrite->add_rewrite_tag("%$taxonomy%", '([^/]+)', $args['query_var'] ? "{$args['query_var']}=" : "taxonomy=$taxonomy&term=");
     299        if ( $args['hierarchical'] && $args['hierarchical_url'] )
     300            $wp_rewrite->add_rewrite_tag("%$taxonomy%", '.*?/?([^/]+)', $args['query_var'] ? "{$args['query_var']}=" : "taxonomy=$taxonomy&term=");
     301        else
     302            $wp_rewrite->add_rewrite_tag("%$taxonomy%", '([^/]+)', $args['query_var'] ? "{$args['query_var']}=" : "taxonomy=$taxonomy&term=");
    299303        $wp_rewrite->add_permastruct($taxonomy, "{$args['rewrite']['slug']}/%$taxonomy%", $args['rewrite']['with_front']);
    300304    }
     
    26112615
    26122616    $slug = $term->slug;
     2617    $t = get_taxonomy($taxonomy);
    26132618
    26142619    if ( empty($termlink) ) {
    2615         $t = get_taxonomy($taxonomy);
    26162620        if ( $t->query_var )
    26172621            $termlink = "?$t->query_var=$slug";
     
    26202624        $termlink = home_url($termlink);
    26212625    } else {
    2622         $termlink = str_replace("%$taxonomy%", $slug, $termlink);
     2626        if ( $t->hierarchical_url ) {
     2627            $hierarchical_slugs = array();
     2628            $ancestors = get_ancestors($term->term_id, $taxonomy);
     2629            foreach ( (array)$ancestors as $ancestor ) {
     2630                $ancestor_term = get_term($ancestor, $taxonomy);
     2631                $hierarchical_slugs[] = $ancestor_term->slug;
     2632            }
     2633            $hierarchical_slugs = array_reverse($hierarchical_slugs);
     2634            $hierarchical_slugs[] = $slug;
     2635            $termlink = str_replace("%$taxonomy%", implode('/', $hierarchical_slugs), $termlink);
     2636        } else {
     2637            $termlink = str_replace("%$taxonomy%", $slug, $termlink);
     2638        }
    26232639        $termlink = home_url( user_trailingslashit($termlink, 'category') );
    26242640    }
Note: See TracChangeset for help on using the changeset viewer.