WordPress函数:get_sidebar(获取侧边栏)

描述

引入当前主题的模板文件 sidebar.php 。如果使用特定的名字 ($name) ,那么就会引用包含这个特定名字的模板文件 sidebar-{name}.php 。

如果主题没有 sidebar.php 文件,就会引入默认的 wp-includes/theme-compat/sidebar.php 。

用法

&lt;?php <a href="https://www.wpdaxue.com/tag/get_sidebar" title="查看与【get_sidebar】相关的文章" target="_blank" rel="noopener">get_sidebar</a>( $name ); ?&gt;

参数

$name

(string) (可选) 调用 sidebar-name.php.

默认: None

例子

404页面

下面的代码是一个简单模板文件,专门用来显示 “HTTP 404: Not Found” 错误的 (这个文件应该包含在你的主题中,名为 404.php

&lt;?php get_header(); ?&gt;
&lt;h2&gt;Error 404 - Not Found&lt;/h2&gt;
&lt;?php <a href="https://www.wpdaxue.com/tag/get_sidebar" title="查看与【get_sidebar】相关的文章" target="_blank" rel="noopener">get_sidebar</a>(); ?&gt;
&lt;?php get_footer(); ?&gt;

左边栏和右边栏

一个主题包含2个边栏。

&lt;?php get_header(); ?&gt;
&lt;?php get_sidebar('left'); ?&gt;
&lt;?php get_sidebar('right'); ?&gt;
&lt;?php get_footer(); ?&gt;

右边栏和左边栏的名字应该分别命名为 sidebar-right.php 和 sidebar-left.php。

多个边栏

不同页面使用不同边栏

&lt;?php
if ( is_home() ) :
	get_sidebar( 'home' );
elseif ( is_404() ) :
	get_sidebar( '404' );
else :
	get_sidebar();
endif;
?&gt;

首页和404页面专用的边栏的名字应该分别为 sidebar-home.php 和 sidebar-404.php。

资源文件

get_sidebar() 包含在 wp-includes/general-template.php.

相关函数

get_header(), get_footer(), get_template_part(), get_search_form(),comments_template()

来源:

https://www.wpdaxue.com/get_sidebar.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_32307.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?