wordpress不同分类下调用不同文章single模板

作者: 小默 分类: Wordpress交流, 首页 发布时间: 2019-12-28 16:52 ė
Warning: Use of undefined constant the_views - assumed 'the_views' (this will throw an Error in a future version of PHP) in /www/wwwroot/www.seohave.com/wp-content/themes/TangStyle/single.php on line 19
12,335 人访问
6没有评论

WordPress不同分类下的文章使用不同文章样式:
WordPress不同分类下的文章使用不同文章模板样式实现的方法和上面说到的方法二的原理是一样的,只不过使用的函数不是is_category ,而是 in_category 。
例一:
同样我们要根据需要创建两个以上的文章模板样式,比如single1.php、single2.php和single3.php,然后在single.php通过in_category 判断代码来实现自己需要的效果。

比如要实现id为8、9、10三个分类下的文章使用single1.php样式,id为1、2、3的分类下的文章使用single2.php样式,其余使用single3.php样式!首先,复制三个single.php文件分别取名为“single1.php”、“single2.php”和“single3.php”,然后,把原先的single.php文件里面的内容全部删除,并用下面的代码进行替换:

2 if ( in_category(array(8,9,10)) ) {
3 include(TEMPLATEPATH . '/single1.php');
4 }
5 elseif ( in_category(array(1,2,3))){
6 include(TEMPLATEPATH . '/single2.php');
7 }
8 else {
9 include(TEMPLATEPATH . '/single3.php');
10 }
11 ?>

<?phpif( in_category(array(8,9,10)) ) {include(TEMPLATEPATH . '/single1.php');}elseif( in_category(array(1,2,3))){include(TEMPLATEPATH . '/single2.php');}else{include(TEMPLATEPATH . '/single3.php');}?>

可以直接复制

本文出自 建站seo运营,转载时请注明出处及相应链接。

本文永久链接: https://www.seohave.com/644.html

0

发表回复

Ɣ回顶部