WordPress为不同页面使用不同头部

来源:网络时间:2011-04-21 13:01:58

  你是不经常遇到这种情形,你希望对不同的分类运用不同的头部样式?我确定你肯定有这种需求。这里有一些简单有效的解决方案让你能够维布通的主题定义不同的头部样式。如果你需要更细节的内容,你可以去查看wordpress的开发文档。
  首先你要为不同的分类创建不同的头部文件,需要有一个头部文件是默认的。这些文件将会被包含于主要的header.php 文件。下面的代码就是wordpress 主题模板需要的代码。


/**** Conditional Header for Per Category Example Wordpress ****/
// make sure we are in category listing
if (is_category()){
if (is_category(’1′)){

}
elseif (is_category(’2′)){

}
else {
// this is the deafult header

}
}
?>
下面是用分类的名字和别名的例子
// Alternative for using Category ID, You can use Category Name or Slug
if (is_category()){
// example of using a category name
if (is_category(’Category 1′)){

}
// example of using category slug
elseif (is_category(’category-1′)){

}
else {
// this is the deafult header

}
}
?>


  可能你也想为不同的页面使用不同的头部文件,所以我也把下面的代码例子写了出来。
//
// example of using header file based on pages
// note that you can either use page ID, Page Name or Page Slug
//
// this one uses page title
if (is_page(’About’)){

}
// this one uses page slug
elseif (is_page(’subscribe’)){

}
// this one uses page ID
elseif (is_page(’6′)){

}
else {

}
?>


  提示:你需要根据你的实际情况用上面这些代码写入你的header.php文件来加载特殊的头部元素。

文章内容来源于网络,不代表本站立场,若侵犯到您的权益,可联系我们删除。(本站为非盈利性质网站) 联系邮箱:rjfawu@163.com
多特网友 2013-09-20 21:01:58 回复
非常感谢分享这个~~ 成功设置了不同的页面,不同的顶图了 谢谢~
多特网友 2012-07-21 10:12:39 回复
这些代码放在哪个文件里,放在什么地方呢
多特网友 2013-09-20 21:01:58 回复
非常感谢分享这个~~ 成功设置了不同的页面,不同的顶图了 谢谢~
多特网友 2012-07-21 10:12:39 回复
这些代码放在哪个文件里,放在什么地方呢