【问题标题】:widget menu does not appear in wordpress admin menu小部件菜单未出现在 wordpress 管理菜单中
【发布时间】:2015-01-27 21:25:20
【问题描述】:

我正在尝试在我的主题中创建自己的小部件区域。这是我在function.php中使用的代码

函数front_widget_area(){

 register_sidebars ( 3, $args)
 $args = array(
'name'          => __('row1 %d'),
'id'            => 'row1',
'description'   => '',
'class'         => '',
'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', 'front_widget_area');

我还没有实现与我想要放置小部件的页面相关的代码部分。问题是。当我将此代码放入 function.php 时,小部件菜单应该在管理面板中可见,不是吗?..但不是,有人可以帮我找出原因吗?提前致谢

【问题讨论】:

    标签: wordpress widget sidebar


    【解决方案1】:

    这是我用来创建小部件的代码

    register_sidebar(array(
            'id' => '',
            'name' => '',
            'before_widget' => '',
            'after_widget' => '',
            'before_title' => '',
            'after_title' => '',
    ));
    

    我通常不会将我的小部件代码包装在函数周围,我只是将它按原样放在函数文件中。

    希望对你有帮助

    【讨论】:

    • 所以没有 add_action()?
    【解决方案2】:

    此代码对我有用。

    $sidebar_args = array(
        'name'          => __('row1 %d'),
        'id'            => 'row1',          
        'description'   => '',
        'class'         => '',
        'before_widget' => '<li id="%1$s" class="widget %2$s">',
        'after_widget'  => '</li>',
        'before_title'  => '<h2 class="widgettitle">',
        'after_title'   => '</h2>' 
    );
    register_sidebars ( 3, $sidebar_args);
    

    似乎register_sidebars 不需要add_action 行。 如果您只想注册一个侧边栏,add_action 是必需的。

    WP Codex - register_sidebars

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-16
      • 1970-01-01
      • 1970-01-01
      • 2017-04-04
      • 2014-03-06
      • 1970-01-01
      • 2019-10-27
      相关资源
      最近更新 更多