WordPress获取侧边栏函数get_sidebar用法
发布时间:2025-10-19 15:08:57 本站作者 【 字体:大 中 小 】 浏览:83 次
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');?> 热门推荐
最新发布
酱骨架的家常做法
材料骨架,盐,老抽,白酒做法1.骨架用盐和少许老抽,白酒腌制.不加水2.把腌制好的骨架扔进高压锅,中火,上气后调小火五分钟,关火,焖一会儿再打开锅盖3.接下来要做的就是啃了,喜欢喝酒可以一边喝酒一边啃,很爽吧...
咕噜肉最正宗的做法
咕噜肉又称甜酸肉或咕咾肉,是广东的一道汉族传统名菜,属于粤菜,以甜酸汁及猪肉煮成。这道菜是欧美人士最熟悉的中国菜之一,因此广见于中国以外的唐人街的餐馆。咕噜肉的主料去皮五花猪肉500克,熟鲜笋肉150克,鸡蛋液30克,辣椒25克,葱段5克,蒜泥,芝麻油各5克,精盐1.5克,汾酒7.5克,湿淀粉40克,干淀粉...
东坡肉最正宗的做法
东坡肉(滚肉、红烧肉)是杭州名菜,用猪肉炖制而成。其色、香、味俱佳,深受人们喜爱。慢火,少水,多酒,是制作这道菜的诀窍。一般是一块约二寸许的方正形猪肉,一半为肥肉,一半为瘦肉,入口香糯、肥而不腻,带有酒香,色泽红亮,味醇汁浓,酥烂而形不碎,十分美味。东坡肉的材料猪五花肋肉1000克,葱100克,冰糖...
木须肉最正宗的做法
一点鸡蛋,一点黄瓜,少许肉片,就能做出我很喜欢吃的木须肉了。木须肉的材料猪肉150克,鸡蛋2个,黄瓜50克,木耳5克,葱花、姜末、盐、料酒、香油、味精、淀粉各适量木须肉的做法1.将鸡蛋打入碗中,先取少量蛋清放入一个干净的碗中,再用筷子将剩下的鸡蛋搅打均匀。2.猪肉洗净切成薄片,用刚才预留的...






