Warning: Undefined variable $ex_word in /www/wwwroot/yunfuwuqi.chinazhx.cn/wp-content/themes/lsw_FB6LDT/lsw/functions.php on line 133
Warning: Undefined variable $case in /www/wwwroot/yunfuwuqi.chinazhx.cn/wp-content/themes/lsw_FB6LDT/lsw/functions.php on line 133
Warning: Undefined variable $ex_word in /www/wwwroot/yunfuwuqi.chinazhx.cn/wp-content/themes/lsw_FB6LDT/lsw/functions.php on line 134
Warning: Undefined variable $case in /www/wwwroot/yunfuwuqi.chinazhx.cn/wp-content/themes/lsw_FB6LDT/lsw/functions.php on line 134
Warning: Undefined variable $case in /www/wwwroot/yunfuwuqi.chinazhx.cn/wp-content/themes/lsw_FB6LDT/lsw/functions.php on line 136
Warning: Undefined variable $ex_word in /www/wwwroot/yunfuwuqi.chinazhx.cn/wp-content/themes/lsw_FB6LDT/lsw/functions.php on line 138
Warning: Undefined variable $ex_word in /www/wwwroot/yunfuwuqi.chinazhx.cn/wp-content/themes/lsw_FB6LDT/lsw/functions.php on line 133
Warning: Undefined variable $case in /www/wwwroot/yunfuwuqi.chinazhx.cn/wp-content/themes/lsw_FB6LDT/lsw/functions.php on line 133
Warning: Undefined variable $ex_word in /www/wwwroot/yunfuwuqi.chinazhx.cn/wp-content/themes/lsw_FB6LDT/lsw/functions.php on line 134
Warning: Undefined variable $case in /www/wwwroot/yunfuwuqi.chinazhx.cn/wp-content/themes/lsw_FB6LDT/lsw/functions.php on line 134
Warning: Undefined variable $case in /www/wwwroot/yunfuwuqi.chinazhx.cn/wp-content/themes/lsw_FB6LDT/lsw/functions.php on line 136
Warning: Undefined variable $ex_word in /www/wwwroot/yunfuwuqi.chinazhx.cn/wp-content/themes/lsw_FB6LDT/lsw/functions.php on line 138
wordpress不同分类调用不同模板方法(自定义调用分类目录), 很多时候我们需要对于不同的分类展示不同的模板, 这个时候我们就需要指定调用一个分类, 其实也是比较好实现, 我们可以判定是不是这个分类, 如果是我们就直接调用, 如果不是我们调用其他的分类.
<?php>$post=$wp_query->post; if(in_category('1')){ include(TEMPLATEPATH.'/category-1.php'); } elseif(in_category('2')){ include(TEMPLATEPATH./'category-2.php'); } else{ include(TEMPLATEPATH.'/category-3.php'); } ?>
上面的这串代码的意思, 如果分类目录id为1的目录存在(in_category(‘1′)那么就调用category-1.php, 如果不存在那么久直接调用category-2.php模板, 如果俩个条件都不满足那么就实现include(TEMPLATEPATH.’/category-3.php’);调用这个.
<?php $post=$wp_query->post; if(in_category(‘7′)) { include(TEMPLATEPATH.‘/archive-view.php’);} elseif(in_category(‘12′)) { include(TEMPLATEPATH.‘/single12.php’); } elseif(in_category(‘42′)) { include(TEMPLATEPATH.‘/single42.php’); } else{include(TEMPLATEPATH.‘/archive-other.php’); } ?>
其实这个方法跟第一个类似, 但是可以无限延伸, 比如你想在id未42的目录显示single42.php这个模板, 那么就点击打开这个分类的时候就会判定是不是在这个目录, 如果是就直接显示, 如果不是那么就不显示.