我已经创建了一个自定义的帖子类型‘演示文稿’,我已经在我的主菜单中添加了存档页面。我的层次菜单是:
会议(空链接: href="#")
--公司(空链接: href="#")
-演示文稿(CPT存档页面)
我想添加类'current-menu-ancestor‘和'current-menu-parent',如下所示:
会议(空链接: href="#")‘当前菜单祖先’
-- Société(空链接: href="#") 'current-menu-parent‘
-page (CPT存档页面)当前菜单
我该怎么做呢?谢谢
发布于 2016-10-05 04:55:57
我不确定这就是你想要的,但你可以修改它以使条件适合你。尝试对$classes , $item, $args使用print_r();。
此外,请检查Codex references
function filter_handler( $classes , $item, $args, $depth ){
if (in_array('current-menu-item', $item->classes) OR in_array('current_page_item', $item->classes)) {
if ( 'presentations' == get_post_type() ) {
if ( $depth == 0 ) {
$classes[] = 'current-menu-ancestor';
}
if ( $depth == 1 ) {
$classes[] = 'current-menu-parent';
}
if ( $depth == 2 ) {
$classes[] = 'current-menu';
}
}
}
return $classes;
}
add_filter( 'nav_menu_css_class', 'filter_handler', 10, 4 );https://stackoverflow.com/questions/39859031
复制相似问题