[英]Wordpress Issue with Walker Class
What does an Illegal offset type in isset or empty, I have never ran into this error message before? isset或null中的非法偏移类型是什么,我以前从未遇到过此错误消息? Could you explain this message to me, please?
你能告诉我这个信息吗?
Have also place code that learning how to do in here the reviews 在这里也有放置代码以学习如何做的评论
<?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";
}
Warning: Illegal offset type in isset or empty in /Users/brandonpowell/sites/valet/wordpress-development/web/wp/wp-includes/class-wp-walker.php on line 140警告:第140行的/Users/brandonpowell/sites/valet/wordpress-development/web/wp/wp-includes/class-wp-walker.php中isset中的偏移量类型为非法或为空
This error happen when you use Walker
instead of Walker_Nav_Menu
in extends
. 当您在
extends
使用Walker
而不是Walker_Nav_Menu
,会发生此错误。 You should use this instead: 您应该改用以下代码:
class Walker_Nav_Primary extends Walker_Nav_Menu {
Walker_Nav_Menu
heritate itself of Walker
class, and provide the proper properties / methods for your own walker class. Walker_Nav_Menu
继承了Walker
类的自身,并为您自己的walker类提供适当的属性/方法。
You are extending Walker class. 您正在扩展Walker类。 Therefore you have to define db_fields in your class, it is mandatory.
因此,您必须在类中定义db_fields,这是强制性的。 You wouldn't need it if you have extended Walker_Nav_Menu class.
如果您扩展了Walker_Nav_Menu类,则不需要它。 Example:
例:
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";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.