WordPress 101 主题开发教程: 14 – 通过WalkerClass编辑菜单

WordPress 101 – Part 14: Edit the menu with the Walker Class – Part 1

视频学习参考:https://www.youtube.com/watch?v=ArEmwJV6M7s&list=PLriKzYyLb28nUFbe0Y9d-19uVkOnhYxFE&index=14

WalkerClass 真是之前没有发现的宝藏

通过这个类的子类Walker_Nav_menu 来实现

结构在主题根目录建立Inc文件夹

建立文件walker.php

在functions.php中编写 require get_template_directory() . ‘inc/walker.php’;

在walker.php中编写构建菜单的类