WordPress获取侧边栏函数get_sidebar用法
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');?>上一篇:WordPress获取搜索表单函数get_search_form用法
栏 目:WordPress
下一篇:WordPress获取评论模板函数comments_template用法
本文标题:WordPress获取侧边栏函数get_sidebar用法
本文地址:https://zz.feitang.co/CMSjiaocheng/25143.html
您可能感兴趣的文章
- 11-11wordpress导航菜单新窗口打开的设置方法
- 11-11WP-PostViews插件如何修改文章阅读数
- 11-11wordpress附件保存目录改为年月日和上传文件重命名为时间戳
- 11-11WordPress 上传媒体库文件重命名 全格式支持
- 11-11解决wordpress安装后更新或者上传文件权限不足的问题
- 11-11wordpress实现主动推送+熊掌号推送同步进行
- 11-11WordPress 添加友情链接设置 nofollow 属性
- 11-11WordPress 实现 wp_list_bookmarks 自定义友情链接排除调用
- 11-11WordPress首页指定或排除某分类文章显示
- 11-11WordPress不同分类调用不同的文章模板


阅读排行
推荐教程
- 09-22wordpress如何添加描述
- 11-11wordpress附件保存目录改为年月日和上传文件重命名为时间戳
- 10-19纯代码给WordPress网站添加独立下载页面功能
- 11-11WordPress之给文章内容中间插入广告的实现方法
- 10-18wordpress无插件调用随机文章的方法
- 10-18WordPress 技巧:WordPress 后台也使用七牛云存储
- 10-24Win10无法调节声音怎么办?Win10无法调节声音的解决方法
- 10-19WordPress上传图片HTTP错误的解决方法
- 10-18让注册用户可以上传自己的头像的WordPress插件-WP User Avatar v2.
- 11-11国外WordPress精美主题如何DIY汉化成中文版呢?





