手机
当前位置:查字典教程网 >网页设计 >交互设计教程 >WordPress为不同的页面使用不同的头部文件
WordPress为不同的页面使用不同的头部文件
摘要:在wordpress中如何为不同的分类定义不同的头部文件你是不经常遇到这种情形,你希望对不同的分类运用不同的头部样式?我确定你肯定有这种需求...

 在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文件来加载特殊的头部元素。

【WordPress为不同的页面使用不同的头部文件】相关文章:

用户界面设计经验分享:界面设计技巧分享

网页设计颜色冷暖与明暗

一个美国高管眼里的中国电商

六月设计圈最新干货合集第一波

格式塔在页面设计中的应用

25个移动APP图表设计欣赏

2014年50个年度最佳扁平风格网站设计

在版式设计中一图多用的处理技巧

页面设计中的层次感

25个令人心动不已的全屏网站欣赏

精品推荐
分类导航