Languages: English • Русский • 中文(简体) • (Add your language)
引入 你主题文件夹中当前的 sidebar.php 模板文件。
若参数 $name 被指定,则有特定的 sidebar sidebar-{name}.php 被引入。 若 sidebar-{name}.php 并不存在,则会寻找 sidebar.php
如果主题中并不包含 sidebar.php 文件,则会使用默认主题的 sidebar 文件:wp-includes/theme-compat/sidebar.php
<?php get_sidebar( $name ); ?>
假定你的有 wp-content/yourTheme/sidebar-nice-bar.php 文件。那你能在某个页面引入该边栏(sidebar)的方式是
<?php get_header('nice-bar'); ?>
以下是一个应对 "HTTP 404: Not Found" 错误的模板示例,你可以在主题的 404.php) 中引入。
<?php get_header(); ?> <h2>Error 404 - Not Found</h2> <?php get_sidebar(); ?> <?php get_footer(); ?>
在一个主题中使用两个边栏(sidebar)。
<?php get_header(); ?> <?php get_sidebar( 'left' ); ?> <?php get_sidebar( 'right' ); ?> <?php get_footer(); ?>
左右边栏响应的文件名分别是 sidebar-left.php 和 sidebar-right.php
对不同页面引用不同的边栏。
<?php if ( is_home() ) : get_sidebar( 'home' ); elseif ( is_404() ) : get_sidebar( '404' ); else : get_sidebar(); endif; ?>
如上,对应于首页(home)和404的不同边栏分别为 sidebar-home.php 和 sidebar-404.php 。
get_sidebar() 在 wp-includes/general-template.php
中。
Widgets: is_active_widget(), the_widget(), register_widget(), unregister_widget(), wp_register_widget_control(), wp_unregister_widget_control(), wp_convert_widget_settings(), wp_get_widget_defaults(), wp_widget_description()