IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    WordPress 主题开发:get_sidebar()

    zuley发表于 2017-02-09 15:50:16
    love 0

    说明

    从当前的主题目录加载模板文件sidebar.php。如果指定了名称,那么将加载头部文件sidebar-{name}.php

    如果当前主题没有sidebar.php文件,将加载默认的wp-includes/theme-compat/sidebar.php

    用法

    <?php get_sidebar($name); ?>
    

    参数

    参数名 类型 默认 说明
    $name 字符串(可选) 无 调用sidebar-{name}.php文件

    示例

    <?php
        # 如果是首页,则调用 sidebar-home.php 文件
        if (is_home()) {
            get_sidebar('home');
        # 如果是404页面,则调用 sidebar-404.php 文件
        } elseif (is_404()) {
            get_sidebar('404');
        # 其他的则调用 sidebar.php 文件
        } else {
            get_sidebar();
        }
    ?>
    

    参考

    官方链接:https://codex.wordpress.org/Function_Reference/get_sidebar



沪ICP备19023445号-2号
友情链接