Advertisement
rAthus

[WordPress] custom template selon custom category

Nov 20th, 2018
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.63 KB | None | 0 0
  1. // Arthur - custom template selon custom category
  2. add_filter('single_template','check_for_category_single_template');
  3. function check_for_category_single_template($t) {
  4.     $cats = get_the_terms(get_the_ID(),'project-type');
  5.     foreach((array)$cats as $cat) {
  6.         if (file_exists(get_stylesheet_directory().'/single-'.$cat->slug.'.php'))
  7.             return get_stylesheet_directory().'/single-'.$cat->slug.'.php';
  8.         if ($cat->parent) {
  9.             $cat = get_the_category_by_ID($cat->parent);
  10.             if (file_exists(get_stylesheet_directory().'/single-'.$cat->slug.'.php'))
  11.                 return get_stylesheet_directory().'/single-'.$cat->slug.'.php';
  12.         }
  13.     }
  14.     return $t;
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement