Changeset 15705
- Timestamp:
- 10/04/2010 10:37:25 AM (14 years ago)
- Location:
- trunk/wp-includes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/canonical.php
r15615 r15705 155 155 156 156 $obj = $wp_query->get_queried_object(); 157 158 if ( $term_count <= 1 && !empty($obj->term_id) && ( $tax_url = get_term_link((int)$obj->term_id, $obj->taxonomy) )159 && !is_wp_error($tax_url) && $redirect['query']) {160 if ( is_category() ) {161 $redirect['query'] = remove_query_arg( array( 'category_name', 'category', 'cat'), $redirect['query']);162 } elseif ( is_tag() ) {163 $redirect['query'] = remove_query_arg( array( 'tag', 'tag_id'), $redirect['query']);164 } elseif ( is_tax() ) { // Custom taxonomies will have a custom query var, remove those too:165 $tax = get_taxonomy( $obj->taxonomy );166 if ( false !== $tax->query_var)167 $redirect['query'] = remove_query_arg($tax->query_var, $redirect['query']);168 else169 $redirect['query'] = remove_query_arg( array( 'term', 'taxonomy'), $redirect['query']);157 if ( $term_count <= 1 && !empty($obj->term_id) && ( $tax_url = get_term_link((int)$obj->term_id, $obj->taxonomy) ) && !is_wp_error($tax_url) ) { 158 if ( !empty($redirect['query']) ) { 159 if ( is_category() ) { 160 $redirect['query'] = remove_query_arg( array( 'category_name', 'category', 'cat'), $redirect['query']); 161 } elseif ( is_tag() ) { 162 $redirect['query'] = remove_query_arg( array( 'tag', 'tag_id'), $redirect['query']); 163 } elseif ( is_tax() ) { // Custom taxonomies will have a custom query var, remove those too: 164 $tax = get_taxonomy( $obj->taxonomy ); 165 if ( false !== $tax->query_var) 166 $redirect['query'] = remove_query_arg($tax->query_var, $redirect['query']); 167 else 168 $redirect['query'] = remove_query_arg( array( 'term', 'taxonomy'), $redirect['query']); 169 } 170 170 } 171 172 171 $tax_url = parse_url($tax_url); 173 172 if ( ! empty($tax_url['query']) ) { // Custom taxonomies may only be accessable via ?taxonomy=..&term=.. … … 177 176 $redirect['path'] = $tax_url['path']; 178 177 } 179 180 178 } 181 179 } elseif ( is_single() && strpos($wp_rewrite->permalink_structure, '%category%') !== false ) { -
trunk/wp-includes/taxonomy.php
r15690 r15705 271 271 272 272 $defaults = array( 'hierarchical' => false, 273 'hierarchical_url' => false, 273 274 'update_count_callback' => '', 274 275 'rewrite' => true, … … 296 297 'with_front' => true, 297 298 )); 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="); 299 303 $wp_rewrite->add_permastruct($taxonomy, "{$args['rewrite']['slug']}/%$taxonomy%", $args['rewrite']['with_front']); 300 304 } … … 2611 2615 2612 2616 $slug = $term->slug; 2617 $t = get_taxonomy($taxonomy); 2613 2618 2614 2619 if ( empty($termlink) ) { 2615 $t = get_taxonomy($taxonomy);2616 2620 if ( $t->query_var ) 2617 2621 $termlink = "?$t->query_var=$slug"; … … 2620 2624 $termlink = home_url($termlink); 2621 2625 } 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 } 2623 2639 $termlink = home_url( user_trailingslashit($termlink, 'category') ); 2624 2640 }
Note: See TracChangeset
for help on using the changeset viewer.