目前,每个类别都有一个单独的模板(category-1.php、category-2.php等),就我而言,有一百多个。我想将其重构为4,例如,如果$cat在1范围内。。20,如果在范围21内,则呈现“first\\u category.php”。。50,呈现“second\\u category.php”等。
谢谢
目前,每个类别都有一个单独的模板(category-1.php、category-2.php等),就我而言,有一百多个。我想将其重构为4,例如,如果$cat在1范围内。。20,如果在范围21内,则呈现“first\\u category.php”。。50,呈现“second\\u category.php”等。
谢谢
如果您可以使用template_redirect
钩子和一个简单的函数来设置要使用的模板
add_action( \'template_redirect\', \'category_set_redirect\' );
function category_set_redirect(){
//create the sets of categories
$first_set= array("1","2","3","4","5","6");
$second_set= array("7","8","9","10","11","12");
if (is_category()){
if (in_array(get_query_var(\'cat\'),$first_set)){
include(TEMPLATEPATH . "/first_category.php"); // include the corresponding template
die();
}
if (in_array(get_query_var(\'cat\'),$second_set)){
include(TEMPLATEPATH . "/second_category.php"); // include the corresponding template
die();
}
}
}
我正在开发一个主题,有一个奖项和;认证只包含4-6个小徽标。有没有办法将这些图片分类,然后用简单的代码将所有这些图片显示在主页上,这样客户端就不必进入源代码?谢谢