最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

walker - Manual use of Walker_Category class

programmeradmin2浏览0评论

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.
发布评论

评论列表(0)

  1. 暂无评论