我试图在wordpress中进行模板重定向,但部分成功
function ahaali_qa_theme_redirect(){
global $wp;
$plugindir = dirname(__FILE__);
if(is_archive()){
$tname = \'archive-question.php\';
if(file_exists(TEMPLATEPATH.\'/\'.$tname)){
$returntemplate = TEMPLATEPATH.\'/\'.$tname;
}else{
$returntemplate = $plugindir.\'/default-template/\'.$tname;
}
ahaali_do_theme_redirect($returntemplate);
}elseif(is_single()){
$tname = \'single-question.php\';
if(file_exists(TEMPLATEPATH.\'/\'.$tname)){
$returntemplate = TEMPLATEPATH.\'/\'.$tname;
}else{
$returntemplate = $plugindir.\'/default-template/\'.$tname;
}
ahaali_do_theme_redirect($returntemplate);
}elseif(is_archive() && is_tax(\'question_category\')){
$tname = \'taxonomy-question_category.php\';
if(file_exists(TEMPLATEPATH.\'/\'.$tname)){
$returntemplate = TEMPLATEPATH.\'/\'.$tname;
}else{
$returntemplate = $plugindir.\'/default-template/\'.$tname;
}
ahaali_do_theme_redirect($returntemplate);
}
}
除了is\\u tax()之外,其他一切都正常,有人能解释一下我是怎么做的,或者我做错了什么吗?
非常感谢。