2017-05-22 167 views
-1

我在頁面tolkeuddannelsen.dk上收到error500。通過錯誤日誌,我可以在我的主題function.php中找到它的93-185行,這是造成麻煩的原因。這是我的網絡主機說的: 後端致命錯誤:PHP致命錯誤:無法在/ var/www /中重新聲明thim_widgets_inits()(以前在/var/www/www.tolkeuddannelsen.dk/www/functions.php:93中聲明) www.tolkeuddannelsen.dk/www/wp-content/themes/elearningwp/functions.php on line 185 \ n,referer:http://tolkeuddannelsen.dk/錯誤500:PHP致命錯誤:無法重新聲明thim_widgets_inits()

這些行代碼看起來像這樣。

function thim_widgets_inits() { 
    register_sidebar(array(
     'name'   => __('Sidebar 1', 'thim'), 
     'id'   => 'sidebar-1', 
     'description' => 'Left Sidebar', 
     'before_widget' => '<aside id="%1$s" class="widget %2$s">', 
     'after_widget' => '</aside>', 
     'before_title' => '<h4 class="widget-title">', 
     'after_title' => '</h4>', 
    )); 

// register_sidebar(array(
//  'name'   => __('Sidebar 2', 'thim'), 
//  'id'   => 'sidebar-2', 
//  'description' => 'Right Sidebar', 
//  'before_widget' => '<aside id="%1$s" class="widget %2$s">', 
//  'after_widget' => '</aside>', 
//  'before_title' => '<h4 class="widget-title">', 
//  'after_title' => '</h4>', 
// )); 

    register_sidebar(array(
     'name'   => 'Top Drawer', 
     'id'   => 'drawer_top', 
     'description' => __('Drawer Top', 'thim'), 
     'before_widget' => '<aside id="%1$s" class="widget %2$s">', 
     'after_widget' => '</aside>', 
     'before_title' => '<h4 class="widget-title">', 
     'after_title' => '</h4>', 
    )); 
    register_sidebar(array(
     'name'   => __('Offcanvas', 'thim'), 
     'id'   => 'offcanvas_sidebar', 
     'description' => 'Drawer Right', 
     'before_widget' => '<aside id="%1$s" class="widget %2$s">', 
     'after_widget' => '</aside>', 
     'before_title' => '<h4 class="widget-title">', 
     'after_title' => '</h4>', 
    )); 

    register_sidebar(array(
     'name'   => 'Menu Right', 
     'id'   => 'menu_right', 
     'description' => __('Menu Right', 'thim'), 
     'before_widget' => '<li id="%1$s" class="widget %2$s">', 
     'after_widget' => '</li>', 
     'before_title' => '<h3>', 
     'after_title' => '</h3>', 
    )); 
    register_sidebar(array(
     'name'   => 'Footer', 
     'id'   => 'footer', 
     'description' => __('Footer Sidebar', 'thim'), 
     'before_widget' => '<aside id="%1$s" class="widget %2$s footer_widget">', 
     'after_widget' => '</aside>', 
     'before_title' => '<h4 class="widget-title">', 
     'after_title' => '</h4>', 
    )); 

    register_sidebar(array(
     'name'   => 'Copyright', 
     'id'   => 'copyright', 
     'description' => __('Copyright', 'thim'), 
     'before_widget' => '<aside id="%1$s" class="widget %2$s">', 
     'after_widget' => '</aside>', 
     'before_title' => '<h4 class="widget-title">', 
     'after_title' => '</h4>', 
    )); 
    register_sidebar(array(
     'name'   => __('Sidebar Shop', 'thim'), 
     'id'   => 'shop', 
     'description' => 'Shop Sidebar', 
     'before_widget' => '<aside id="%1$s" class="widget %2$s">', 
     'after_widget' => '</aside>', 
     'before_title' => '<h4 class="widget-title">', 
     'after_title' => '</h4>', 
    )); 
    if (class_exists('LearnPress')) { 
     register_sidebar(array(
      'name'   => 'Top Sidebar Courses', 
      'id'   => 'top_sidebar_courses', 
      'description' => __('Top Sidebar Courses', 'thim'), 
      'before_widget' => '', 
      'after_widget' => '', 
      'before_title' => '<h3>', 
      'after_title' => '</h3>', 
     )); 

     register_sidebar(array(
      'name'   => 'Sidebar Courses', 
      'id'   => 'sidebar_courses', 
      'description' => __('Sidebar Courses', 'thim'), 
      'before_widget' => '<aside id="%1$s" class="widget %2$s">', 
      'after_widget' => '</aside>', 
      'before_title' => '<h4 class="widget-title">', 
      'after_title' => '</h4>', 
     )); 
    } 
} 

任何人都可以幫助我解決這個問題嗎?謝謝!

回答

0

這是因爲你正在重新聲明你已經聲明的函數。

使用這一個:

function thim_widgets_inits_child() { 
    register_sidebar(array(
     'name'   => __('Sidebar 1', 'thim'), 
     'id'   => 'sidebar-1', 
     'description' => 'Left Sidebar', 
     'before_widget' => '<aside id="%1$s" class="widget %2$s">', 
     'after_widget' => '</aside>', 
     'before_title' => '<h4 class="widget-title">', 
     'after_title' => '</h4>', 
    )); 

// register_sidebar(array(
//  'name'   => __('Sidebar 2', 'thim'), 
//  'id'   => 'sidebar-2', 
//  'description' => 'Right Sidebar', 
//  'before_widget' => '<aside id="%1$s" class="widget %2$s">', 
//  'after_widget' => '</aside>', 
//  'before_title' => '<h4 class="widget-title">', 
//  'after_title' => '</h4>', 
// )); 

    register_sidebar(array(
     'name'   => 'Top Drawer', 
     'id'   => 'drawer_top', 
     'description' => __('Drawer Top', 'thim'), 
     'before_widget' => '<aside id="%1$s" class="widget %2$s">', 
     'after_widget' => '</aside>', 
     'before_title' => '<h4 class="widget-title">', 
     'after_title' => '</h4>', 
    )); 
    register_sidebar(array(
     'name'   => __('Offcanvas', 'thim'), 
     'id'   => 'offcanvas_sidebar', 
     'description' => 'Drawer Right', 
     'before_widget' => '<aside id="%1$s" class="widget %2$s">', 
     'after_widget' => '</aside>', 
     'before_title' => '<h4 class="widget-title">', 
     'after_title' => '</h4>', 
    )); 

    register_sidebar(array(
     'name'   => 'Menu Right', 
     'id'   => 'menu_right', 
     'description' => __('Menu Right', 'thim'), 
     'before_widget' => '<li id="%1$s" class="widget %2$s">', 
     'after_widget' => '</li>', 
     'before_title' => '<h3>', 
     'after_title' => '</h3>', 
    )); 
    register_sidebar(array(
     'name'   => 'Footer', 
     'id'   => 'footer', 
     'description' => __('Footer Sidebar', 'thim'), 
     'before_widget' => '<aside id="%1$s" class="widget %2$s footer_widget">', 
     'after_widget' => '</aside>', 
     'before_title' => '<h4 class="widget-title">', 
     'after_title' => '</h4>', 
    )); 

    register_sidebar(array(
     'name'   => 'Copyright', 
     'id'   => 'copyright', 
     'description' => __('Copyright', 'thim'), 
     'before_widget' => '<aside id="%1$s" class="widget %2$s">', 
     'after_widget' => '</aside>', 
     'before_title' => '<h4 class="widget-title">', 
     'after_title' => '</h4>', 
    )); 
    register_sidebar(array(
     'name'   => __('Sidebar Shop', 'thim'), 
     'id'   => 'shop', 
     'description' => 'Shop Sidebar', 
     'before_widget' => '<aside id="%1$s" class="widget %2$s">', 
     'after_widget' => '</aside>', 
     'before_title' => '<h4 class="widget-title">', 
     'after_title' => '</h4>', 
    )); 
    if (class_exists('LearnPress')) { 
     register_sidebar(array(
      'name'   => 'Top Sidebar Courses', 
      'id'   => 'top_sidebar_courses', 
      'description' => __('Top Sidebar Courses', 'thim'), 
      'before_widget' => '', 
      'after_widget' => '', 
      'before_title' => '<h3>', 
      'after_title' => '</h3>', 
     )); 

     register_sidebar(array(
      'name'   => 'Sidebar Courses', 
      'id'   => 'sidebar_courses', 
      'description' => __('Sidebar Courses', 'thim'), 
      'before_widget' => '<aside id="%1$s" class="widget %2$s">', 
      'after_widget' => '</aside>', 
      'before_title' => '<h4 class="widget-title">', 
      'after_title' => '</h4>', 
     )); 
    } 
} 

在使用行動

add_action('init','thim_widgets_inits_child'); 
+0

謝謝!!後我應該刪除已經存在的這個add_action並將其替換爲你的嗎? add_action('widgets_init','thim_widgets_inits'); –

+0

是的,你可以用add_action('widgets_init','thim_widgets_inits_child')替換它。 –

+0

嗯。現在我嘗試了它,但它仍然沒有工作。它可能是別的嗎? –

相關問題