WordPress.org

Plugin Directory

Changeset 389052


Ignore:
Timestamp:
05/25/11 18:28:24 (3 years ago)
Author:
leogermani
Message:

adds a new level to template locate hierarchy. so it will try to look for the single-post_type.php for the original post type

File:
1 edited

Legend:

Unmodified
Added
Removed
  • multi-language-framework/trunk/parse_query.php

    r379839 r389052  
    4646            $wp_query->query_vars['name'] = $wp_query->query_vars['pagename']; 
    4747            $wp_query->query_vars[$wp_query->query_vars['post_type']] =  $wp_query->query_vars['name']; 
    48             $wp_query->query_vars['pagename'] = '';             
     48            $wp_query->query_vars['pagename'] = ''; 
     49            $wp_query->is_page = false; 
     50            $wp_query->is_single = true; 
    4951 
    5052 
     
    5860            ); 
    5961             
     62            // Lets add the template for the original post type in the template hierarchy of this post. 
     63            add_filter('single_template', 'mlf_add_single_template'); 
    6064             
    6165        } 
     
    6670    } 
    6771     
     72} 
     73 
     74function mlf_add_single_template($templates) { 
     75 
     76    global $wp_query; 
     77     
     78    $post_type = $wp_query->query_vars['post_type']; 
     79     
     80    if (preg_match('/(.+)_t_([a-zA-Z]{2})/', $post_type)) 
     81        $orig_post_type = preg_replace('/(.+)_t_([a-zA-Z]{2})/', "$1", $post_type); 
     82     
     83    $new_templates = array(); 
     84    $new_templates[] = "single-$post_type.php"; 
     85    $new_templates[] = "single-$orig_post_type.php"; 
     86    $new_templates[] = 'single.php'; 
     87 
     88    return locate_template($new_templates); 
     89 
    6890} 
    6991 
Note: See TracChangeset for help on using the changeset viewer.