get_sidebar()导入sidebar.php文件

目录

描述

 

  • 导入sidebar.php文件。
  • 如果设置了参数 $name ,则会导入sidebar-{name}.php文件。
  • 如果主题文件夹中没有sidebar-{name}.php文件,则导入wordpress默认主题的sidebar.php文件(wp-includes/theme-compat/sidebar.php)。

get_sidebar() 描述

用法

<?php get_sidebar$name ); ?>

get_sidebar() 用法

参数

$name

(string) (可选) Calls for sidebar-name.php.

默认值: None

get_sidebar() 参数

示例

Simple call

Assume you have file wp-content/yourTheme/sidebar-nice-bar.php. The way you can include this sidebar in your page is:

Simple 404 page

The following code is a simple example of a template for an "HTTP 404: Not Found" error (which you could include in your Theme as 404.php).

Left and Right Sidebars

Two sidebars in one theme.

The file names for the right and left sidebars should be sidebar-right.php and sidebar-left.php respectively.

Multi sidebars

Different sidebar for different pages.

The file names for the home and 404 sidebars should be sidebar-home.php and sidebar-404.php respectively.

get_sidebar() 示例

注意

get_sidebar() 注意

历史

  • 添加于 版本: 1.5.0
  • 2.5.0 : 添加 'name' 参数.

get_sidebar() 历史

源文件

get_sidebar() 函数的代码位于 wp-includes/general-template.php.

get_sidebar() 源文件

相关