WordPress加载侧边栏模板标签:get_sidebar

WordPress模板标签get_sidebar用于加载侧边栏模板,即sidebar.php

get_sidebar( string $name = null )

get_sidebar标签默认加载sidebar.php,但可以通过传递一个参数来实现加载类似sidebar-name.php的模板:


以上示例加载sidebar-name.php,如果sidebar-name.php文件不存在,则加载sidebar.php

对于三栏布局,我们需要两个侧边栏,分别为sidebar-left.php和sidebar-right.php,相应的代码如下:





get_sidebar函数的用法与get_header函数是一样的,更多用法请阅读:

WordPress模板标签:get_header

扩展阅读

get_sidebar()函数位于:wp-includes/general-template.php

相关函数:

原创文章,作者:,如若转载,请注明出处:https://ce.771633.xyz/1496.html

Like (0)
Previous 2025年3月8日
Next 2025年3月8日

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注