如何清除WP主题上的小部件的侧栏ID错误

问题描述 投票:0回答:1

自定义主题在显示器上抛出一个php错误。该错误表示设置侧栏ID但不确定如何设置它。错误:“register_sidebar被错误地调用。在”我的边栏“侧边栏的参数数组中没有设置id。默认为”sidebar-1“。手动将id设置为”sidebar-1“以使此通知静音并保留现有侧边栏内容。”

我尝试删除自定义主题并替换它。

这是主题函数sidebar.php:

 <div class="span4 ">
            <!-- *** SIDEBAR START *** -->
     <aside class="sidebar">
        <div class="widget categories">
          <?php   /* Widgetized sidebar, if you have the plugin installed. */
           if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
           <?php wp_list_categories('title_li=Cat'); ?>
           <?php the_tags(); ?>
          <?php endif; ?>
        </div><!-- end categories -->
    </aside><!--end sidebar-->
  <!-- *** SIDEBAR END *** -->

  </div>

认为可以在/wp-includes/widgets.php中完成,它有fn:register_sidebars

function register_sidebars( $number = 1, $args = array() ) {
    global $wp_registered_sidebars;
    $number = (int) $number;

    if ( is_string($args) )
        parse_str($args, $args);

    for ( $i = 1; $i <= $number; $i++ ) {
        $_args = $args;

        if ( $number > 1 )
            $_args['name'] = isset($args['name']) ? sprintf($args['name'], $i) : sprintf(__('Sidebar %d'), $i);
        else
            $_args['name'] = isset($args['name']) ? $args['name'] : __('Sidebar');

        // Custom specified ID's are suffixed if they exist already.
        // Automatically generated sidebar names need to be suffixed regardless starting at -0
        if ( isset($args['id']) ) {
            $_args['id'] = $args['id'];
            $n = 2; // Start at -2 for conflicting custom ID's
            while ( is_registered_sidebar( $_args['id'] ) ) {
                $_args['id'] = $args['id'] . '-' . $n++;
            }
        } else {
            $n = count( $wp_registered_sidebars );
            do {
                $_args['id'] = 'sidebar-' . ++$n;
            } while ( is_registered_sidebar( $_args['id'] ) );
        }
        register_sidebar($_args);
    }
}

这是来自widgets.php的register_sidebar函数:

function register_sidebar($args = array()) {
    global $wp_registered_sidebars;

    $i = count($wp_registered_sidebars) + 1;

    $id_is_empty = empty( $args['id'] );

    $defaults = array(
        'name' => sprintf(__('Sidebar %d'), $i ),
        'id' => "sidebar-$i",
        'description' => '',
        'class' => '',
        'before_widget' => '<li id="%1$s" class="widget %2$s">',
        'after_widget' => "</li>\n",
        'before_title' => '<h2 class="widgettitle">',
        'after_title' => "</h2>\n",
    );

    $sidebar = wp_parse_args( $args, $defaults );

    if ( $id_is_empty ) {
        /* translators: 1: the id argument, 2: sidebar name, 3: recommended id value */
        _doing_it_wrong( __FUNCTION__, sprintf( __( 'No %1$s was set in the arguments array for the "%2$s" sidebar. Defaulting to "%3$s". Manually set the %1$s to "%3$s" to silence this notice and keep existing sidebar content.' ), '<code>id</code>', $sidebar['name'], $sidebar['id'] ), '4.2.0' );
    }

    $wp_registered_sidebars[$sidebar['id']] = $sidebar;

    add_theme_support('widgets');

    /**
     * Fires once a sidebar has been registered.
     *
     * @since 3.0.0
     *
     * @param array $sidebar Parsed arguments for the registered sidebar.
     */
    do_action( 'register_sidebar', $sidebar );

    return $sidebar['id'];
}
php wordpress themes
1个回答
0
投票

换线:

function register_sidebar($args = array()) {

至:

function register_sidebars($args = array()) {
© www.soinside.com 2019 - 2024. All rights reserved.