Advertisement
Guest User

Untitled

a guest
May 3rd, 2012
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.36 KB | None | 0 0
  1. <?php
  2. class moulding_templates {
  3.     public static function determine_template(){
  4.         global $post,$wp_query;
  5.  
  6.         // custom post types
  7.         $post_type_array = array('moulding_profiles','moulding_combination','moulding_collection','idea_gallery');
  8.         foreach ($post_type_array as $post_type_single) {
  9.             global $post;
  10.             if (is_singular($post_type_single)) {
  11.                 moulding_templates::loadSingleTemplate($post);
  12.             }
  13.         }
  14.         // custom taxonomies
  15.         $taxonomy_array = array('profile_categories','combination_categories','wood_types');
  16.         foreach ($taxonomy_array as $taxonomy_single) {
  17.             if (is_tax($taxonomy_single)) {
  18.                 moulding_templates::loadTaxonomyTemplate($taxonomy_single);
  19.             }
  20.         }
  21.     }
  22.  
  23.     private static function loadSingleTemplate($post) {
  24.         $template_name = 'moulding-templates/single-'.$post->post_type.'.php';
  25.         $template = locate_template(array($template_name), true);
  26.         if(empty($template)) {
  27.             include(MOULDINGS_BASE_DIR . 'includes/' . $template_name);
  28.             exit();
  29.         }
  30.     }
  31.     private static function loadTaxonomyTemplate($taxonomy) {
  32.         $template_name = 'moulding-templates/taxonomy-'.$taxonomy.'.php';
  33.         $template = locate_template(array($template_name), true);
  34.         if(empty($template)) {
  35.             include(MOULDINGS_BASE_DIR . 'includes/' . $template_name);
  36.             exit();
  37.         }
  38.     }
  39. }
  40. add_action('template_include', array('moulding_templates', 'determine_template'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement