WordPress函数介绍——获取侧边栏函数get_sidebar详解。

get_sidebar函数位于wp-includes/general-template.php第100行左右,函数原型如下:
function get_sidebar( $name = null ) {/**
* Fires before the sidebar template file is loaded.
*
* The hook allows a specific sidebar template file to be used in place of the
* default sidebar template file. If your file is called sidebar-new.php,
* you would specify the filename in the hook as get_sidebar( 'new' ).
*
* @since 2.2.0
* @since 2.8.0 $name parameter added.
*
* @param string|null $name Name of the specific sidebar file to use. null for the default sidebar.
*/do_action( 'get_sidebar', $name );$templates = array();$name = (string) $name;if ( '' !== $name )$templates[] = "sidebar-{$name}.php";$templates[] = 'sidebar.php';locate_template( $templates, true );}由上述代码可以看出,get_sidebar函数需要一个字符串类型参数,该参数可以为空,为空时会自动查找主题目录下的sidebar.php文件作为侧边栏,如果主题目录下没有sidebar.php文件将会使用默认的 wp-includes/theme-compat/sidebar.php 文件作为侧边栏。如果传入参数,则会引入sidebar-参数名.php作为侧边栏。
<?php get_sidebar();?>
如果使用传入参数dAImadog,将会加载主题目录下sidebar-daimadog.php文件作为侧边栏。
<?php get_sidebar('daimadog');?>
安装KB5014697补丁以后开启热点无法上网怎么办?
Windows 11 的最新星期二补丁KB5014697更...(627 )人阅读时间:2025-11-25
Win11本地安全策略在哪里?Win11添加IP 安全策略的
IP安全策略是一个给予通讯分析的策略,当我们配置好IP安全...(948 )人阅读时间:2025-11-25
Win11字体显示不全如何解决?Win11字体显示不全解决方
Win11系统是当前最好用的系统之一,在给用户带来全新界面...(752 )人阅读时间:2025-11-25
Win11怎么创建虚拟磁盘?Win11创建虚拟磁盘的方法
虚拟磁盘就是用内存中虚拟出一个或者多个磁盘的技术。和虚拟内...(607 )人阅读时间:2025-11-25