常用函数-get_sidebar()

0条评论

说明

该函数从当前主题文件夹中包含sidebar.php模板文件。如果指定了名称,那么函数将包含一个特殊的侧边栏文件sidebar-special.php。如果主题中没有sidebar.php文件,那么函数会包含来自默认主题wp-content/themes/default/sidebar.php的侧边栏文件。

用法

<?php get_sidebar( $name ); ?>

参数

$name

(字符串)(可选)对sidebar-name.php的调用

默认值:None

示例

简单的404页面

下面是一个为“HTTP 404: Not Found”错误(在主题文件中为404.php)而制作的简单模板。

<?php get_header(); ?>
<h2>Error 404 - Not Found</h2>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

左侧侧边栏和右侧侧边栏

一个主题中包含两个侧边栏

<?php get_header(); ?>
<?php get_sidebar('left'); ?>
<?php get_sidebar('right'); ?>
<?php get_footer(); ?>

多个侧边栏

不同页面上的不同侧边栏

<?php
if ( is_home() ) :
get_sidebar('home');
elseif ( is_404() ) :
get_sidebar('404');
else :
get_sidebar();
endif;
?>

注释

  • name参数引入于WP 2.5

历史记录

  • 始见于1.5.0版本

源文件

get_sidebar()位于wp-includes/general-template.php中。

相关资源

get_header, get_sidebar, get_search_form, comments_template, get_footer()

 

发表新评论

此内容将保密,不会被其他人看见。
  • 自动将网址与电子邮件地址转变为链接。
  • 允许HTML标签:<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • 自动断行和分段。

更多关於格式化选项的信息

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.