专业WORDPRESS主题设计制作

register_sidebar()函数(register用法举例)

发布于: 2022-08-19

register_sidebar()函数注册一个单独的侧边栏区域和返回ID












<?php register_sidebar( 
    array(
        'name'          => '侧边栏',
        'id'            => 'unique-sidebar-id',
        'description'   => '',
        'class'         => '',
        'before_widget' => '<div class="s-con text-center">',
        'after_widget'  => '</div>',
        'before_title'  => '<h2 class="widgettitle">',
        'after_title'   => '</h2>' 
    )
); ?>

参数

register_sidebar()函数

name – 侧边栏的名字(默认是 ‘Sidebar’ 加 数字 ID)
id – 侧边栏 ID,必须全部小写,不带空格(默认是一个自动递增的数字 ID)
description – 用来说明侧边栏是什么,在哪里显示的文字。会在小工具管理界面显示。(默认为空)
class – 分配到小工具 HTML输出中的CSS选择器名字(默认为空)
before_widget – 在每个小工具前面输出的 HTML代码(默认: ‘<li id=”%1$s” class=”widget %2$s”>’)
after_widget – 在每个小工具后面输出的 HTML代码(默认: “</li>”)
before_title – 在标题前输出的 HTML代码(默认: <h2 class=”widgettitle”>)
after_title – 在标题后输出的 HTML代码(默认:”</h2>”)

WP技术资料 wordpress模板制作、wordpress主题开发相关知识常见问题总结
MORE
服务电话:
0533-2765967

微信 13280692153