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函数讲解》的一些看法。更多内容请查看本栏目更多内容!
装置SAE上的wordpress,创立使用抉择wordpress模板,装置后是3.4版本 新建一个版本2,下载最新wordpress装置...
办法一:应用<!--more-->标签来自在的截取字数 在模板中应用the_content()函数来打印内容,在文章中经过点击...
在主题的function.php文件中,能够找到形如如下内容的语句:复制代码代码如下:if ( function_exists(&lsquo...
函数引见 update_option()用于更新数据表中存在的选项值。该函数可取代add_option,但不迭add_option灵敏。...
很多采纳WordPress顺序搭建的博客都相当注重与读者之间的互动,以评论为例,为了进步读者的体验品质,有的博...
首先,在主题functions.php中添加上面的代码: 复制代码代码如下:function wp_dashboard_GongGao() { if...