rozanchetta

WordPress - Cat Filha com Template da Cat Pai

Oct 27th, 2011
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.77 KB | None | 0 0
  1. // FUNÇÃO QUE FAZ AS CATEGORIAS FILHAS USAREM O MESMO TEMPLATE DA CATEGORIA PAI
  2. function load_cat_parent_template($template) {
  3. $cat_ID = absint( get_query_var('cat') );
  4. $category = get_category( $cat_ID );
  5. $templates = array();
  6. if ( !is_wp_error($category) )
  7. $templates[] = "category-{$category->slug}.php";
  8. $templates[] = "category-$cat_ID.php";
  9. if ( !is_wp_error($category) ) {
  10. $category = $category->parent ? get_category($category->parent) : '';
  11. if( !empty($category) ) {
  12. if ( !is_wp_error($category) )
  13. $templates[] = "category-{$category->slug}.php";
  14. $templates[] = "category-{$category->term_id}.php";
  15. }
  16. }
  17. $templates[] = "category.php";
  18. $template = locate_template($templates);
  19. return $template;
  20. }
  21. add_action('category_template', 'load_cat_parent_template');
  22.  
Advertisement
Add Comment
Please, Sign In to add comment