Advertisement
miriamdepaula

WordPress: Alterando estrutura de permalinks das categorias

Jul 22nd, 2011
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.66 KB | None | 0 0
  1. //modifica a estrutura de permalinks das categorias. Ex: /category/subcategory/postname
  2.  
  3. add_filter( 'category_link', 'new_category_link', 10, 2 );
  4. function new_category_link( $catlink, $category_id )
  5. {
  6.     global $wp_rewrite;
  7.     $catlink = $wp_rewrite->get_category_permastruct();
  8.  
  9.     if ( empty( $catlink ) ) {
  10.         $catlink = home_url('?cat=' . $category_id);
  11.     } else {
  12.         $category = &get_category( $category_id );
  13.         $category_nicename = $category->slug;
  14.  
  15.         $catlink = str_replace( '%category%', $category_nicename, $catlink );
  16.         $catlink = home_url( user_trailingslashit( $catlink, 'category' ) );
  17.     }
  18.     return $catlink;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement