register_sidebar和白屏错误

时间:2014-09-06 07:01:06

标签: php wordpress codex

我需要为主题注册侧边栏。 我已将此代码添加到functions.php

的末尾
<?php
include("widget.php");
 function farad_widgets_init(){
register_sidebar(array(
         'id' => 'sidebar-1',
        'name' =>  'left-sidebar',
        'description' =>  'farad' ,
        'before_widget' => '<aside id="%1$s" class="widget %2$s">',
        'after_widget' => "</aside>",
        'before_title' => '<h2 class="widget-title">',
        'after_title' => '</h2>',
    ) );
}
add_action( 'widgets_init', 'farad_widgets_init' ); 
?>

在我添加了代码后,wp-login.php显示了一个白色屏幕。

问题是什么?

2 个答案:

答案 0 :(得分:1)

删除开始和结束的php(<?php ?>)标记。在最后一个函数之后你很可能没有关闭你的php标签,所以你按原样添加你的代码,你创建了一个语法错误,因为你已经在一个已经打开的php标签中有一个开放的php标签

此外,删除include()部分,没有必要

答案 1 :(得分:0)

只需将此代码放在function.php中,您将获得左侧边栏。

function farad_widgets_init(){
register_sidebar(array(
         'id' => 'sidebar-1',
        'name' =>  'left-sidebar',
        'description' =>  'farad' ,
        'before_widget' => '<aside id="%1$s" class="widget %2$s">',
        'after_widget' => "</aside>",
        'before_title' => '<h2 class="widget-title">',
        'after_title' => '</h2>',
    ) );
}
add_action( 'widgets_init', 'farad_widgets_init' );