register_sidebar()(创立侧边栏)
建设一个侧边栏,用来搁置小工具。这个函数应用的时分请放在一个函数里,挂载到 “widgets_init” 钩子。
用法
register_sidebar( $args );
参数
$args
(字符串 | 数组)(可选)要创立的侧边栏的参数。
默许值:
$args = array( 'name' => __( 'Sidebar name', 'theme_text_domain' ), 'id' => 'unique-sidebar-id', 'description' => '', 'class' => '', 'before_widget' => '<li id="%1" class="widget %2">', 'after_widget' => '</li>', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>' );
数组参数引见:
例子
register_sidebar( array( 'name' => __( '左边的侧边栏' ), 'id' => 'sidebar-1', 'description' => __( '右侧边栏的小工具。' ), 'before_title' => '<h3 class="title">', 'after_title' => '</h3 class="title">', ));
其它
该函数位于:wp-includes/widgets.php
get_sidebar()(获取侧边栏)
get_sidebar() 用来引入侧边栏模板。假如指定称号则引入以后主题根目录的 sidebar-{name}.php 文件,不指定则引入以后主题根目录的 sidebar.php 文件,假如文件不存在则引入 wp-includes/theme-compat/sidebar.php 文件。
用法
get_sidebar( $name );
参数
$name
(字符串)(可选)引入模板的称号,假如指定则引入以后主题根目录的 sidebar-{$name}.php 文件。
默许值:None
例子
下边的代码将引入以后主题根目录的 sidebar.php 文件:
<?php get_sidebar(); ?>
下边的代码将引入以后主题根目录的 sidebar-left.php 文件:
<?php get_sidebar( 'left' ); ?>
下边的例子辨别引入了左侧边栏(sidebar-left.php)和右侧边栏(sidebar-right.php):
<?php get_header(); ?> <?php get_sidebar( 'left' ); ?>
内容内容
<?php get_sidebar( 'right' ); ?> <?php get_footer(); ?>
其它
此函数位于:wp-includes/general-template.php
以上就是安达网络工作室关于《WordPress中用于创建以及获取侧边栏的PHP函数讲解》的一些看法。更多内容请查看本栏目更多内容!
这里选取的例子,便是 WordPress 中比拟有名的丑化超链接Title成果,普通的 title 成果是把鼠标放到 a 元素...
wordpress能够设置自定义字段,不便扩大性能,wordpress利用巧妙的数据库表设计达到这一目的,posts表寄存文...
很多WordPress站长都常常遭到渣滓评论的滋扰,针对这种状况,采纳上面的代码可能会对你有所协助。将以下代码...
本文实例讲述了WordPress评论中制止HTML代码显示的办法。分享给大家供大家参考。详细剖析如下: 应用WordPr...
1、在仪表盘增加子菜单: add_submenu_page( 'index.php', … ); 2、在文章处增加子菜单: add_submenu...
复制代码代码如下: //该办法为向曾经存在的菜单中增加子菜单 function add_submenu() { add_submenu_page( ...