【函数介绍】
get_sidebar()函数是用于包含我们主题中的sidebar.php模板文件。你也可以指定自己的边栏文件名,命名格式为:sidebar-{$name}.php。
说明:如果主题中没有sidebar.php文件,那么函数会包含来自默认主题wp-content/themes/default/sidebar.php的侧边栏文件。
【函数使用】
<?php get_sidebar( $name ); ?>
【参数说明】
$name
(string) (可选) 边栏php文件名sidebar-name.php.
Default: None
【函数实例】
404页面(你主题下的404.php)模板使用get_sidebar()获取边栏文件:
<?php get_header(); ?>
<h2>Error 404 - Not Found</h2>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
调用左边栏与右边栏:
<?php get_header(); ?>
<?php get_sidebar('left'); ?>
<?php get_sidebar('right'); ?>
<?php get_footer(); ?>
不同页面上的不同侧边栏
<?php
if ( is_home() ) :
get_sidebar('home');
elseif ( is_404() ) :
get_sidebar('404');
else :
get_sidebar();
endif;
?>