参考了老外的思路,改进了下代码,可以支持ID和别名判断.
用法:
原category.php
改名为category-default.php
,新建一个category.php
文件用来做入口,代码片段如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | $catid = get_query_var('cat'); if ( file_exists(TEMPLATEPATH . '/category-' . $catid . '.php') ) die(include( TEMPLATEPATH . '/category-' . $catid . '.php')); $cat = &get_category($catid); if ( file_exists(TEMPLATEPATH . '/category-' . $cat->slug . '.php') ) die(include( TEMPLATEPATH . '/category-' . $cat->slug . '.php')); $parent = $cat->category_parent; while ($parent){ $cat = &get_category($parent); if ( file_exists(TEMPLATEPATH . '/category-' . $cat->cat_ID . '.php') ) die(include (TEMPLATEPATH . '/category-' . $cat->cat_ID . '.php')); if ( file_exists(TEMPLATEPATH . '/category-' . $cat->slug . '.php') ) die(include (TEMPLATEPATH . '/category-' . $cat->slug . '.php')); } include (TEMPLATEPATH . '/category-default.php'); |
code 插件 用的是什么? 效果挺不错的
样式表是自己写的,什么插件都一样.