如何在WordPress Genesis子主题中注册小部件?

如何在WordPress Genesis子主题中注册小部件?,wordpress,genesis,Wordpress,Genesis,我正试图在WordPress的Genesis子主题中注册一个新的小部件区域。代码似乎不起作用,导致我的网站崩溃。有人能告诉我我做错了什么吗?我试图让它超越所有页面的内容。这是我的代码: genesis_register_sidebar( array( 'id' => ‘above_content’, 'name' => __( ‘Above Content’, 'domain' ), 'description' => __

我正试图在WordPress的Genesis子主题中注册一个新的小部件区域。代码似乎不起作用,导致我的网站崩溃。有人能告诉我我做错了什么吗?我试图让它超越所有页面的内容。这是我的代码:

genesis_register_sidebar( array(
    'id'          => ‘above_content’,
    'name'        => __( ‘Above Content’, 'domain' ),
    'description' => __( ‘Above the content’, 'domain' ),
));

add_action( 'genesis_before_loop’, ‘above_content’ );
function your_widget() {
if ( is_active_sidebar(‘above_content’) ) {
    genesis_widget_area( ‘above_content’, array(
     'before' => '<div class=“above_content widget-area">',
     'after'     => '</div>',
   )); 
  }
}
genesis\u寄存器\u侧栏(数组(
“id”=>“高于内容”,
“名称”=>uuuuu('over Content','domain'),
'description'=>uuu('content'、'domain'上方),
));
添加动作('genesis_before_loop','over_content');
函数您的_小部件(){
如果(是否处于活动状态\u侧栏(“内容上方”){
genesis_widget_区域(“内容上方”,数组(
'在'=>之前'两件事:

  • 确保您使用的是标准引号
    ,而不是卷曲引号
  • 为您的操作分配适当的回调
  • genesis\u寄存器\u侧栏(数组(
    “id”=>“高于内容”,
    “名称”=>uuuuu('over Content','domain'),
    'description'=>uuu('content'、'domain'上方),
    ) );
    添加_操作('genesis_before_loop','your_widget');
    函数您的_小部件(){
    如果(是否处于活动状态\u侧栏(“内容上方”){
    genesis_widget_区域(“内容上方”,数组(
    '在'=>''之前,
    '在'=>''之后,
    ) ); 
    }
    }
    

    如果您想注册另一个小部件,只需注册一个新的侧栏(具有唯一ID),并将新逻辑添加到新的回调函数(或将其添加到您的小部件()。在何处添加此附加小部件取决于您的特定用例。

    您将此代码放在何处?另外,请确保您使用的是标准单引号
    ,而不是卷曲引号
    哇,我甚至没有意识到有不同类型的引号。感谢您指出这一点!我修复了引号,现在小部件显示出来了在我的管理区,但它没有显示在网站上。代码在我的函数文件中。我相信您需要将
    上面的内容
    回调更改为
    您的\u小部件
    。换句话说:
    添加\u操作('genesis\u before\u loop','your\u widget'))
    它成功了!!非常感谢!不过我很好奇,id是否也应该更改?如果我注册另一个小部件会发生什么?它不可能也是您的小部件,对吗?对不起,这对我来说都是全新的!
    genesis_register_sidebar( array(
        'id'          => 'above_content',
        'name'        => __( 'Above Content', 'domain' ),
        'description' => __( 'Above the content', 'domain' ),
    ) );
    
    add_action( 'genesis_before_loop', 'your_widget' );
    function your_widget() {
        if ( is_active_sidebar('above_content') ) {
            genesis_widget_area( 'above_content', array(
               'before' => '<div class="above_content widget-area">',
               'after'  => '</div>',
            ) ); 
        }
    }