Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. add_filter( 'category_rewrite_rules', 'vipx_filter_category_rewrite_rules' );
  2. function vipx_filter_category_rewrite_rules( $rules ) {
  3. $categories = get_categories( array( 'hide_empty' => false ) );
  4.  
  5. if ( is_array( $categories ) && ! empty( $categories ) ) {
  6. $slugs = array();
  7. foreach ( $categories as $category ) {
  8. if ( is_object( $category ) && ! is_wp_error( $category ) ) {
  9. if ( 0 == $category->category_parent ) {
  10. $slugs[] = $category->slug;
  11. } else {
  12. $slugs[] = trim( get_category_parents( $category->term_id, false, '/', true ), '/' );
  13. }
  14. }
  15. }
  16.  
  17. if ( ! empty( $slugs ) ) {
  18. $rules = array();
  19.  
  20. foreach ( $slugs as $slug ) {
  21. $rules[ '(' . $slug . ')/feed/(feed|rdf|rss|rss2|atom)?/?$' ] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
  22. $rules[ '(' . $slug . ')/(feed|rdf|rss|rss2|atom)/?$' ] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
  23. $rules[ '(' . $slug . ')(/page/(d)+/?)?$' ] = 'index.php?category_name=$matches[1]&paged=$matches[3]';
  24. }
  25. }
  26. }
  27. return $rules;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement