我希望这不是一个dup——我找不到它!
我的目标是,在我的自定义walker中,附加current-menu-ancestor
如果菜单项是用户当前所在页面/帖子的祖先(无论有多深),则初始化为菜单项。
我希望这样的事情能奏效:(在我的wp_menu_item_classes_by_context()
等效)
if ($post->post_parent) { // Does the post have parents at all?
$ancestors=get_post_ancestors($post->ID); // Get all ancestors
$root=count($ancestors)-1; // Get the key of the top-level one
$parent = $ancestors[$root]; // Top level ancestor ID
// Finally, see if the ancestor ID is the same as the menu_item\'s post ID
if($parent == $menu_item->ID) $classes[] = "current-menu-ancestor";
}
无济于事。我相信它不会比这复杂得多,但我对Wordpress的特性不是特别精通!