要实现不同WordPress不同分类下的日志调用不同的日志主题,解决办法很简单。
在你的theme目录下找到日志主题(single-theme.php)和plugin目录下的日志主题(single-plugin.php);把默认日志主题single.php复制一份,命名为single-all.php,之后把single.php的内容清空,加入以下代码:
引用
if ( in_category(‘theme’) ) {
include(TEMPLATEPATH . ‘/single-theme.php’);
}
elseif ( in_category(‘plugin’) ) {
include(TEMPLATEPATH . ‘/single-plugin.php’);
}
else {
include(TEMPLATEPATH . ‘/single-all.php’);
}
?>
这段代码的功能是自动判断如果分类的别名是theme,日志就自动调用single-theme.php;分类别名是plugin的话,就自动调用single-plugin.php文件,没指定的话,就自动调用默认的日志主题文件single-all.php,这样就实现了不同分类的日志使用不同主题的目的。
上面的代码也可以改成按分类目录ID来判断:
引用
if ( in_category(‘1’) ) {
include(TEMPLATEPATH . ‘/single-theme.php’);
}
elseif ( in_category(‘2’) ) {
include(TEMPLATEPATH . ‘/single-plugin.php’);
}
else {
include(TEMPLATEPATH . ‘/single-all.php’);
}
?>
如果分类ID为1,就调用single-theme.php文件,分类ID为2,就调用single-plugin.php文件,效果和判断别名是一样的,根据自己爱好选择使用。