Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在wordpress主题中注册侧栏_Php_Wordpress - Fatal编程技术网

Php 在wordpress主题中注册侧栏

Php 在wordpress主题中注册侧栏,php,wordpress,Php,Wordpress,我有一个html模板,我的html中有这段代码,我想在wordpress中转换它 需要设计师吗 我在这里 +1 234 567 876 54 我想把它称为dynamic_sidebar() 如何在functions.php文件中注册边栏 我试着如下 add_action('widgets_init','homepage_widget'); 函数主页(小部件){ 寄存器侧栏(数组)( “名称”=>uuuuuuuuuuuuuuuuu('main homepage','theme slug'),

我有一个html模板,我的html中有这段代码,我想在wordpress中转换它


需要设计师吗

我在这里

+1 234 567 876 54
我想把它称为
dynamic_sidebar()

如何在functions.php文件中注册边栏

我试着如下

add_action('widgets_init','homepage_widget');
函数主页(小部件){
寄存器侧栏(数组)(
“名称”=>uuuuuuuuuuuuuuuuu('main homepage','theme slug'),
'id'=>'homepagelol',
“description”=>(此区域中的小部件将显示在所有帖子和页面上。”,“theme slug”),
“类”=>“橙色”,
'在小部件'=>''之前,
'在小部件'=>''之后,
“在标题“=>”之前,
“在标题“=>”之后,
) );
}

您需要遵循以下几个步骤:

步骤1:注册你的边栏

add_action( 'widgets_init', 'theme_slug_widgets_init' );
function theme_slug_widgets_init() {
    register_sidebar( array(
        'name' => __( 'Main Sidebar', 'theme-slug' ),
        'id' => 'sidebar-1',
        'description' => __( 'Widgets in this area will be shown on all posts and pages.', 'theme-slug' ),
        'before_widget' => '<li id="%1$s" class="widget %2$s">',
    'after_widget'  => '</li>',
    'before_title'  => '<h2 class="widgettitle">',
    'after_title'   => '</h2>',
    ) );
}
add_action('widgets_init','theme_slug_widgets_init');
函数主题\u slug\u小部件\u init(){
寄存器侧栏(数组)(
“名称”=>uuuuuuuuuuu('Main Sidebar','theme slug'),
'id'=>'sidebar-1',
“description”=>(此区域中的小部件将显示在所有帖子和页面上。”,“theme slug”),
'before_widget'=>'
  • ”, 'after_widget'=>'
  • ', “在标题“=>”之前, “在标题“=>”之后, ) ); }
    步骤2:在窗口小部件区域中,您可以看到侧栏,然后添加文本窗口小部件并将html放入文本窗口小部件中

    步骤3:然后调用index.php中的侧栏

    <?php dynamic_sidebar('your-sidebar-unique-id'); ?>
    
    
    
    然后保存页面并重新加载。。 希望这对你有帮助


    谢谢

    您可以尝试使用此代码注册侧边栏,希望对您有所帮助

    if ( function_exists('register_sidebar') )
    register_sidebar(array('name'=>'MiddleSidebar',
    'before_widget' => '<li class="widget">',
    'after_widget' => '</li>',
    'before_title' => '<h2 class="widgettitle">',
    'after_title' => '</h3>',
    ));
    register_sidebar(array('name'=>'FooterSidebar',
    'before_widget' => '<li class="widget">',
    'after_widget' => '</li>',
    'before_title' => '<h2 class="widgettitle">',
    'after_title' => '</h3>',
    ));
    
    if(函数_存在('register_边栏'))
    寄存器侧栏(数组('name'=>'MiddleSidebar',
    'before_widget'=>'
  • ', 'after_widget'=>'
  • ', “在标题“=>”之前, “在标题“=>”之后, )); register_侧栏(数组('name'=>'FooterSidebar', 'before_widget'=>'
  • ', 'after_widget'=>'
  • ', “在标题“=>”之前, “在标题“=>”之后, ));
    您不想将其创建为HTML小部件的具体原因是什么?是的,只需将上面的HTML放在您创建的
    主主页
    侧栏中站点的文本小部件中即可。