web建站教程
  1. 首页
  2. vuejs
  3. js
  4. 好玩
  5. seo教程
  6. 前端知识
  7. 百度echarts
  8. 更多
    php入门
    nodejs
    mockjs
    reactjs
    mysql
    wordpress
    织梦cms
    帝国cms
    git教程
    IT知识
    模板大全
    休息站

wordpress建站:怎么利用get_sidebar实现加载侧边栏模板文件

287 ℃
     

函数原型:

get_sidebar( string $name = null, array $args = array() ): void|false

包含主题的侧边栏模板,或者如果指定了名称,则将包含专门的侧边栏。对于参数 $name,如果文件名为“sidebar-special.php”,则应指定 $name 为:“special”。

参数说明:

$name,指定 sidebar 模板的名称,如果为空则加载 sidebar.php。如果 $name=’special’,则加载 sidebar-specific.php 。

$args,传给 header 模板的参数。

函数源码:

function get_sidebar( $name = null, $args = array() ) {
  do_action( 'get_sidebar', $name, $args );

  $templates = array();
  $name      = (string) $name;
  if ( '' !== $name ) {
    $templates[] = "sidebar-{$name}.php";
  }

  $templates[] = 'sidebar.php';

  if ( ! locate_template( $templates, true, true, $args ) ) {
    return false;
  }
}

包含钩子:

do_action( 'get_sidebar', string|null $name, array $args )

使用举例:

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

wordpress建站如何利用mysql语法批量插入文章

wordpress搭建视频网,视频加载慢怎么解决

wordpress如何实现版本回退

wordpress如何在文章标题上显示置顶标签

wordpress如何在二级目录建站(小编亲测有效)

标签: get_sidebar, wordpress建站, 加载侧边栏模板文件

上面是“wordpress建站:怎么利用get_sidebar实现加载侧边栏模板文件”的全面内容,想了解更多关于 wordpress 内容,请继续关注web建站教程。

当前网址:https://ipkd.cn/webs_4225.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

当前位置: 网站首页 > wordpress
本文共计694个字,预计阅读时长5分钟
生活小工具,收录了80多款小工具
上一篇: 推荐一款宝藏型工具应用类网站——一个木匣
下一篇: 推荐一款拥有江西情怀的免费可商用字体——江西拙楷体
x 打工人ai神器