我试图通过处理自定义帖子类型的插件插入自定义模板文件。除了包含部分的模板外,插件的其余部分都工作得很好。
class ClassName{
public function __construct() {
add_action( \'template_redirect\', array( $this, \'uniThemeRedirect\') );
}
public function uniThemeRedirect(){
global $wp_query;
global $wp;
// Specific Custom Post Type
if( $wp->query_vars["post_type"] == "videos" ){
$templateFilename = "single-videos.php";
if( file_exists( TEMPLATEPATH . \'/\' . $templateFilename ) ){
$return_template = TEMPLATEPATH . \'/\' . $templateFilename;
}
else {
$return_template = UNISLIDER_TEMPLATES . $templateFilename;
}
$this->doThemeRedirect( $return_template );
} else {
echo \'not working\';
}
}
public function doThemeRedirect( $template_url ){
global $post, $wp_query;
if( have_posts() ){
echo $template_url;
require_once ( $template_url );
}
else{
$wp_query->is_404 = true;
}
}
}
$handle = new ClassName();
我正在关注这个
https://stackoverflow.com/questions/4647604/wp-use-file-in-plugin-directory-as-custom-page-template#answer-4975004 实例
但是当我在http://www.domain.com/videos 其中视频是我的自定义帖子类型。
我明白“不工作”意味着没有模板包含
Can anyone please help me what wrong i have done??
UPDATE: This is how i register the Custom Post Type
$labels = array(
\'name\'=>__(\'UniVideos\', \'unislider\'),
\'singular_name\'=>__( \'Videos\', \'unislider\' ),
\'add_new\'=>__( \'Add New\', \'unislider\' ),
\'add_new_item\'=>__( \'Add New Video\' ),
\'edit_item\'=>__(\'Edit Video\'),
\'new_item\'=>__(\'New Video\'),
\'view_item\'=>__(\'View Videos Images\'),
\'search_item\'=>__(\'Search Slide\'),
\'not_found\'=>__(\'Noting Found\'),
\'not_found_in_trash\'=>__(\'Nothing found in Trash\'),
\'parent_item_colon\'=>\'\'
);
$args = array(
\'labels\'=>$labels,
\'public\'=>true,
\'has_archive\'=>true,
\'publicly_queryable\'=>true,
\'show_ui\'=>true,
\'query_var\'=>true,
\'menu_icon\'=>\'\',
\'rewrite\'=>true,
\'capability_type\'=>\'post\',
\'hierarchical\'=>false,
\'menu_position\'=>NULL,
\'supports\'=>array( \'title\' )
);
register_post_type( \'videos\', $args );