我想知道是否可以根据帖子类别的层次结构来定义某些模板。
例如,我有以下类别结构。
->顶级类别
-->第二级分类
->第三级分类
我希望能够做的是使用toplevel.php为任何顶级类别添加,secondlevel.php为任何第二级类别和thirdlevel.php为任何第三级类别。
这有意义吗?基本上每个类别的登陆页都是添加的。
干杯,
发布于 2011-08-29 08:44:45
这是完全有可能的。您可以通过在模板名称' category -slug.php‘中声明模板来创建每个特定类别的模板,或者在模板中指定基于类别更改的特定代码。你应该查看wordpress文档,了解你正在寻找的具体内容:
http://codex.wordpress.org/Category_Templates
你可能想试试这个。发布在Worpress支持论坛上:Original Post
<?php if (is_category()) {
$this_category = get_category($cat);
if (get_category_children($this_category->cat_ID) != "") {
// This is the Template for Category level 1
include(CHILD_DIR.'/maincategory.php');
}
else {
// This is the Template for Category level 2
include(CHILD_DIR.'/subcategory.php');
}
} ?>https://stackoverflow.com/questions/7225014
复制相似问题