非法偏移类型是什么设置或为空,我之前从未遇到此错误消息?你能告诉我这个消息吗?
还要在此处放置学习如何处理评论的代码
<?php
if (has_nav_menu('primary_navigation')) :
wp_nav_menu( array(
'theme_location' => 'primary_navigation',
'menu_class' => 'menu',
'menu_class' => 'mobile-menu',
'walker' => new Walker_Nav_Primary (),
)
);
endif;
?>
class Walker_Nav_Primary extends Walker {
function start_lvl( &$output, $depth = 0, $args = array() ) { //ul
$indent = str_repeat("\t",$depth);
$submenu = ($depth > 0) ? ' sub-menu' : '';
$output .= "\n$indent<ul class=\"fallback$submenu depth_$depth\">\n";
}
警告:第140行/Users/brandonpowell/sites/valet/wordpress-development/web/wp/wp-includes/class-wp-walker.php中isset或为空的非法偏移类型
答案 0 :(得分:4)
在Walker
中使用Walker_Nav_Menu
代替extends
时会发生此错误。你应该改用它:
class Walker_Nav_Primary extends Walker_Nav_Menu {
Walker_Nav_Menu
将自己与Walker
类联系起来,并为自己的步行者类提供适当的属性/方法。
答案 1 :(得分:0)
您正在扩展Walker课程。因此,您必须在类中定义db_fields,它是必需的。如果你扩展了Walker_Nav_Menu,你将不需要它 类。例如:
class Walker_Nav_Primary extends Walker {
// Tell Walker where to inherit it's parent and id values
var $db_fields = array(
'parent' => 'menu_item_parent',
'id' => 'db_id'
);
function start_lvl( &$output, $depth = 0, $args = array() ) { //ul
$indent = str_repeat("\t",$depth);
$submenu = ($depth > 0) ? ' sub-menu' : '';
$output .= "\n$indent<ul class=\"fallback$submenu depth_$depth\">\n";
}