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函数讲解》的一些看法。更多内容请查看本栏目更多内容!
首先列表会变得很臃肿,得到了列表的自身作用——不便用户寻觅真正想要看的帖子,其次,在搜寻引...
找到wp-includes/comment-template.php文件中 复制代码代码如下:if ( empty( $url ) || 'http://' == $url ...
1. 它能够进步用户体验, 调动访客回复的踊跃性, 从而添加评论的数量, 能让博客变得像社区一样活泼. 2. 博客...
目前对大少数人来说是一个无用的性能, 甚至有人以为这是 WordPress 卑劣地偷偷地在页面上埋了一个扯淡的脚本...
去掉logo或许左侧栏的菜单,避免被改掉。 在应用模板下的functions.php下修正 复制代码代码如下: function ...
明天在修正网站的时分,不小心把最新版Wordpress3.5.1的wp-includes目录下的functions.php笼罩出来了,招致...