walker - Manual use of Walker_Category class

Trying to create a menu with category terms as I read in the WP docs "Using Walker Manually": $menu_items = ge

Trying to create a menu with category terms as I read in the WP docs "Using Walker Manually":

$menu_items = get_categories();
$walk = new \Walker_Category();
print_r( $walk->walk( $menu_items, -1 ) );

I get this warning:

Notice: Undefined index: use_desc_for_title in /srv/www/my-site/current/web/wp/wp-includes/class-walker-category.php on line 114

What is the right way to use Walker_category class?

Trying to create a menu with category terms as I read in the WP docs "Using Walker Manually": https://codex.wordpress/Class_Reference/Walker

$menu_items = get_categories();
$walk = new \Walker_Category();
print_r( $walk->walk( $menu_items, -1 ) );

I get this warning:

Notice: Undefined index: use_desc_for_title in /srv/www/my-site/current/web/wp/wp-includes/class-walker-category.php on line 114

What is the right way to use Walker_category class?

Share Improve this question asked Jul 11, 2019 at 7:01 aitoraitor 7252 gold badges8 silver badges23 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

the Walker_Category class you are using requires 3 params in walk() method, the third param will be use_desc_for_title value (this is due to how Walker_Category::start_el() method is written).

In other words, to use the walk() method without generating a notice you should change your last line to

print_r( $walk->walk( $menu_items, -1, -1 ) );

The third param is a boolean:

  • "-1" (or false) - will remove the "title" attribute from the generated menu links
  • "1" ( or true) - will make the menu use category description for the title attribute.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745330174a4622840.html

相关推荐

  • walker - Manual use of Walker_Category class

    Trying to create a menu with category terms as I read in the WP docs "Using Walker Manually": $menu_items = ge

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信