<script type="text/javascript" src="plugin/audioplayer/audio-player.js"></script>
这几天把联盟的主题和插件单独设计了一下模板,于是就要实现不同WordPress不同分类下的日志调用不同的日志主题,解决办法很简单。

single-theme.php和single-plugin.php文件分别是你的theme目录下的日志主题和plugin目录下的日志主题;把默认日志主题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文件,效果和判断别名是一样的,根据自己爱好选择使用。

本文转自:李思章博客  
原文地址:http://lisizhang.com/2279.htm
Tags: , ,
网站相关 | 评论(12) | 引用(0) | 阅读(7135)
福州 Email Homepage
2011/08/07 17:37
路过,来看看。。
全讯网 Email Homepage
2011/07/27 19:55
代码帝啊 。。。 厉害
标语 Email Homepage
2011/07/13 14:51
grin不错!
恋月 Email Homepage
2011/06/19 15:02
这不是WordPress blog 吧 bo 的吧 3.x 后支持自定义文章类型 更方便给力
mbtshose Email Homepage
2011/06/02 17:08
学学博主博客怎么弄
佛像 Email Homepage
2011/05/27 10:19
真的是越玩 越强大啊
nhl jerseys Email Homepage
2011/05/23 15:14
恩,还不错,谢谢博主分享
Cheap DVD Box Sets Email Homepage
2011/05/17 11:28
卢松松博客导航看到贵站,过来支持一下,希望博主能够回访我的博客:http://www.ytq1118.com/
17fenx Email Homepage
2011/04/28 14:49
博客很个性啊
朵朵 Email Homepage
2011/04/28 14:48
没事来坐坐了
分页: 1/2 第一页 1 2 下页 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]