js自定义页眉和页脚
Did you ever see WordPress blogs that have a separate header for different categories? In this tutorial we will share a simple snippet that you can use to add custom header, footer, or even sidebar for each WordPress category.
您是否曾经看到WordPress博客具有针对不同类别的单独标题? 在本教程中,我们将共享一个简单的代码段,您可以使用该代码段为每个WordPress类别添加自定义页眉,页脚甚至边栏。
To call a particular header, you will need to open yourindex.phpand replace your normal header code with this one:
要调用特定的标头,您将需要打开index.php并用以下代码替换普通的标头代码:
<?php if (is_category('Blogging')) {
get_header('blogging');
} else {
get_header();
} ?>
<?php if(is_category('Blogging')){
get_header('blogging');
}其他{
get_header();
}?>
This code above is basically telling WordPress that if someone opens the category called “Blogging” then WordPress needs to display a file called header-blogging.php if it exist. If it does not exist, or if the category is not blogging, then WordPress displays the default header file.
上面的这段代码基本上告诉WordPress,如果有人打开名为“ Blogging”的类别,则WordPress需要显示一个名为header-blogging.php的文件(如果存在)。 如果不存在,或者类别不是博客,则WordPress将显示默认头文件。
To get a separate sidebar for each all you need to do is add the following code:
要为每个单独的侧边栏添加所需的代码,请添加以下代码:
<?php if (is_category('Blogging')) {
get_sidebar('blogging');
} else {
get_sidebar();
} ?>
<?php if(is_category('Blogging')){
get_sidebar('blogging');
}其他{
get_sidebar();
}?>
The code above will look for sidebar-blogging.php to replace the default footer file if the category is Blogging.
如果类别为Blogging,则上面的代码将查找sidebar-blogging.php替换默认的页脚文件。
To get a separate footer for each category all you need to do is add the following code:
要为每个类别获得单独的页脚,您需要做的就是添加以下代码:
<?php if (is_category('Blogging')) {
get_footer('blogging');
} else {
get_footer();
} ?>
<?php if(is_category('Blogging')){
get_footer('blogging');
}其他{
get_footer();
}?>
The code above will look for footer-blogging.php to replace the default footer file if the category is Blogging.
如果类别为Blogging,则上面的代码将查找footer-blogging.php替换默认的页脚文件。
翻译自: /wp-themes/easily-add-custom-header-footer-or-sidebar-for-each-category/
js自定义页眉和页脚