我创建了一个名为“Ad”的自定义帖子类型,然后在该类型下有一个分类法,名为“type”,我在类型类别中添加了一些术语,名为“Radio”、“TV”、“Print”。我希望WordPress使用不同的single.php 每个术语的模板。我想有一个不同于打印模板的广播模板。我试过了taxonomy-ad-type-radio.php 我试过了single-ad-type-radio.php 以及所有其他形式的。有人能告诉我实现这一目标的最佳方法是什么吗?
我已将筛选器添加到functions.php 文件也没有用。我知道我只是错过了一些很容易的事情。非常感谢你的帮助。
<?php 
/** Register the post type for the ads **/
add_action( \'init\', \'register_cpt_ad\' );
function register_cpt_ad() {
    $labels = array( 
        \'name\' => _x( \'Ads\', \'ad\' ),
        \'singular_name\' => _x( \'ad\', \'ad\' ),
        \'add_new\' => _x( \'Add New\', \'ad\' ),
        \'add_new_item\' => _x( \'Add New ad\', \'ad\' ),
        \'edit_item\' => _x( \'Edit ad\', \'ad\' ),
        \'new_item\' => _x( \'New ad\', \'ad\' ),
        \'view_item\' => _x( \'View ad\', \'ad\' ),
        \'search_items\' => _x( \'Search Ads\', \'ad\' ),
        \'not_found\' => _x( \'No ads found\', \'ad\' ),
        \'not_found_in_trash\' => _x( \'No ads found in Trash\', \'ad\' ),
        \'parent_item_colon\' => _x( \'Parent ad:\', \'ad\' ),
        \'menu_name\' => _x( \'Ads\', \'ad\' ),
    );
    $args = array( 
        \'labels\' => $labels,
        \'hierarchical\' => false,
        \'description\' => \'Adbank system\',
        \'supports\' => array( \'title\', \'excerpt\', \'editor\', \'thumbnail\', \'custom-fields\' ),
        \'taxonomies\' => array( \'category\', \'type\', \'campaign\', \'post_tag\' ),
        \'public\' => true,
        \'show_ui\' => true,
        \'show_in_menu\' => true,     
        \'show_in_nav_menus\' => true,
        \'publicly_queryable\' => true,
        \'exclude_from_search\' => false,
        \'has_archive\' => true,
        \'query_var\' => true,
    \'menu_position\' => 3,
        \'can_export\' => true,
        \'rewrite\' => true,
        \'capability_type\' => \'post\'
    );
    register_post_type( \'ad\', $args );
}
/**Register the taxonomy for the ad types**/
add_action( \'init\', \'register_taxonomy_type\' );
function register_taxonomy_type() {
    $labels = array( 
        \'name\' => _x( \'Ad Type\', \'type\' ),
        \'singular_name\' => _x( \'Ad Types\', \'type\' ),
        \'search_items\' => _x( \'Search Ad Type\', \'type\' ),
        \'popular_items\' => _x( \'Popular Ad Type\', \'type\' ),
        \'all_items\' => _x( \'All Ad Type\', \'type\' ),
        \'parent_item\' => _x( \'Parent Ad Types\', \'type\' ),
        \'parent_item_colon\' => _x( \'Parent Ad Types:\', \'type\' ),
        \'edit_item\' => _x( \'Edit Ad Types\', \'type\' ),
        \'update_item\' => _x( \'Update Ad Types\', \'type\' ),
        \'add_new_item\' => _x( \'Add New Ad Types\', \'type\' ),
        \'new_item_name\' => _x( \'New Ad Types\', \'type\' ),
        \'separate_items_with_commas\' => _x( \'Separate ad type with commas\', \'type\' ),
        \'add_or_remove_items\' => _x( \'Add or remove ad type\', \'type\' ),
        \'choose_from_most_used\' => _x( \'Choose from the most used ad type\', \'type\' ),
        \'menu_name\' => _x( \'Ad Type\', \'type\' ),
    );
    $args = array( 
        \'labels\' => $labels,
        \'public\' => true,
        \'show_in_nav_menus\' => true,
        \'show_ui\' => true,
        \'show_tagcloud\' => true,
        \'hierarchical\' => true,
        \'rewrite\' => true,
        \'query_var\' => true
    );
    register_taxonomy( \'type\', array(\'ad\'), $args );
}
/**Register the taxonomy for the campaigns**/
add_action( \'init\', \'register_taxonomy_campaign\' );
function register_taxonomy_campaign() {
    $labels = array( 
        \'name\' => _x( \'Campaigns\', \'campaign\' ),
        \'singular_name\' => _x( \'Campaign\', \'campaign\' ),
        \'search_items\' => _x( \'Search campaigns\', \'campaign\' ),
        \'popular_items\' => _x( \'Popular campaigns\', \'campaign\' ),
        \'all_items\' => _x( \'All campaigns\', \'campaign\' ),
        \'parent_item\' => _x( \'Parent Campaign\', \'campaign\' ),
        \'parent_item_colon\' => _x( \'Parent Campaign:\', \'campaign\' ),
        \'edit_item\' => _x( \'Edit Campaign\', \'campaign\' ),
        \'update_item\' => _x( \'Update Campaign\', \'campaign\' ),
        \'add_new_item\' => _x( \'Add New Campaign\', \'campaign\' ),
        \'new_item_name\' => _x( \'New Campaign\', \'campaign\' ),
        \'separate_items_with_commas\' => _x( \'Separate campaigns with commas\', \'campaign\' ),
        \'add_or_remove_items\' => _x( \'Add or remove campaigns\', \'campaign\' ),
        \'choose_from_most_used\' => _x( \'Choose from the most used campaigns\', \'campaign\' ),
        \'menu_name\' => _x( \'Campaigns\', \'campaign\' ),
    );
    $args = array( 
        \'labels\' => $labels,
        \'public\' => true,
        \'show_in_nav_menus\' => true,
        \'show_ui\' => true,
        \'show_tagcloud\' => true,
        \'hierarchical\' => true,
        \'rewrite\' => true,
        \'query_var\' => true
    );
    register_taxonomy( \'campaign\', array(\'ad\'), $args );
}
function query_post_type($query) {
    $post_types = get_post_types();
    if ( is_category() || is_tag()) {
        $post_type = get_query_var(\'ad\');
        if ( $post_type ) {
            $post_type = $post_type;
        } else {
            $post_type = $post_types;
        }
        $query->set(\'post_type\', $post_type);
        return $query;
    }
}
add_filter(\'pre_get_posts\', \'query_post_type\');
/* NEW STUFF */
// Register the column
function price_column_register( $columns ) {
$columns[\'level\'] = __( \'User Level\', \'my-plugin\' );
return $columns;
}
add_filter( \'manage_edit-ad_columns\', \'price_column_register\' );
// Display the column content
function price_column_display( $column_name, $post_id ) {
if ( \'level\' != $column_name )
    return;
$roles = get_post_meta( $post->ID, \'_members_access_role\', true );
if ($roles == \'level1\') echo \'level1\';
echo \'hello\';
}
add_action( \'manage_posts_custom_column\', \'price_column_display\', 10, 2 );
/**
 * Append the terms of multiple taxonomies to the list
 * of classes generated by post_class().
 *
 * @since 2010-07-10
 * @alter 2012-01-06
 */
function mysite_post_class( $classes, $class, $ID ) {
    $taxonomies = array(
        \'type\',
        \'campaign\',
    );
    $terms = get_the_terms( (int) $ID, $taxonomies );
    if ( is_wp_error( $terms ) || empty( $terms ) )
        return $classes;
    foreach ( (array) $terms as $term ) {
        if ( ! in_array( $term->slug, $classes ) )
            $classes[] = $term->slug;
    }
    return $classes;
}
add_filter( \'post_class\', \'mysite_post_class\', 10, 3 );
add_filter( \'tpicker_taxonomies\', \'my_tpicker_taxonomies\' );
function my_tpicker_taxonomies( $old_taxies) { // Filter taxonomy order
    foreach( array("Categories ", "Campaigns ", "Ad Type " ) as $tax_label) {
        $new_taxies[$tax_label] = $old_taxies[$tax_label];
    }
    return $new_taxies;
}