wordpress不同分类文章日志如何调用不同日志模板

| | Comments (3)



打开single.php模板,以官方模板为例:

原始代码如下:

<?php
/**
 * The Template for displaying all single posts.
 *
 * @package WordPress
 * @subpackage Twenty_Ten
 * @since Twenty Ten 1.0
 */
    get_header();
 ?>

修改为:

<?php
/**
 * The Template for displaying all single posts.
 *
 * @package WordPress
 * @subpackage Twenty_Ten
 * @since Twenty Ten 1.0
 */


if ( in_category('5') ) {
include(TEMPLATEPATH . '/single-5.php');
}
else {
include(TEMPLATEPATH . '/single-all.php');
}

 ?>

这里解释下,这样写后文章就不在调用原先的single.php模板了,在这些代码下面应该还有一些代码,可以删除,执行以上语句后,wp判断为哪个目录调用不同的日志模板,所以必须建立一个通用的模板single-all.php来替代single.php,如果特殊分类比如id为5就会调用single-5.php了。

同样利用in_category()函数可以调用不同的头部文件、侧边拦文件、页脚文件等,这些以前都有提到过了,请参考如下:

为wordpress不同文章不同页面定制不同的侧边栏

WordPress网站开发常用条件标签列表


单点日志:http://spoint.babyshoot.cn

3 Comments

我也在想这个问题,正好用上。谢谢。

谢谢你的分享~

Leave a comment

Archives

Ads by google

Pages

Powered by Movable Type 4.24-en

About this Entry

This page contains a single entry by 单点日志 published on November 20, 2010 12:07 PM.

淘宝网购物要谨慎 数以万计的片子穿梭在淘宝 was the previous entry in this blog.

mysql数据库数据表不能编辑疑似mysql锁表 is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.