自定义主题在显示时抛出php错误。该错误提示您设置边栏ID,但不确定如何设置。 错误:“ register_sidebar被错误地调用。” My 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'];
}
答案 0 :(得分:0)
更改行:
function register_sidebar($args = array()) {
至:
function register_sidebars($args = array()) {
答案 1 :(得分:0)
function register_sidebar($args = array()) {
收件人:
function register_sidebars($args = array()) {
对我有用。