网站地图    收藏   

主页 > 设计 > 网页设计 >

WordPress为不同的页面使用不同的头部文件_交互设

来源:自学PHP网    时间:2015-01-08 09:51 作者: 阅读:

[导读] ...

 在wordpress中如何为不同的分类定义不同的头部文件

你是不经常遇到这种情形,你希望对不同的分类运用不同的头部样式?我确定你肯定有这种需求。这里有一些简单有效的解决方案让你能够维布通的主题定义不同的头部样式。如果你需要更细节的内容,你可以去查看wordpress的开发文档。

首先你要为不同的分类创建不同的头部文件,需要有一个头部文件是默认的。这些文件将会被包含于主要的header.php 文件。下面的代码就是wordpress 主题模板需要的代码。

<?php
/**** Conditional Header for Per Category Example Wordpress ****/
//  make sure we are in category listing
if (is_category()){
if (is_category(’1′)){
<?php include(TEMPLATEPATH.’/header-cat1.php’); ?>
}
elseif (is_category(’2′)){
<?php include(TEMPLATEPATH.’/header-cat2.php’); ?>
}
else {
// this is the deafult header
<?php include(TEMPLATEPATH.’/headerdefault.php’); ?>
}
}
?>

下面是用分类的名字和别名的例子

<?php
//  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′)){
<?php include(TEMPLATEPATH.’/header-cat1.php’); ?>
}
// example of using category slug
elseif (is_category(’category-1′)){
<?php include(TEMPLATEPATH.’/header-cat2.php’); ?>
}
else {
// this is the deafult header
<?php include(TEMPLATEPATH.’/headerdefault.php’); ?>
}
}
?>

可能你也想为不同的页面使用不同的头部文件,所以我也把下面的代码例子写了出来。

<?php
//
// 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’)){
<?php include(TEMPLATEPATH.’/header-contact.php’); ?>
}
// this one uses page slug
elseif (is_page(’subscribe’)){
<?php include(TEMPLATEPATH.’/header-subscribe.php’); ?>
}
// this one uses page ID
elseif (is_page(’6′)){
<?php include(TEMPLATEPATH.’/header-contact.php’); ?>
}
else {
<?php include(TEMPLATEPATH.’/headerdefault.php’); ?>
}
?>

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

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论