我看到在菜单中存在某种层次结构,以找到父级和祖先。
他们寻找“类别或页面”层次结构或“菜单项”层次结构。
但当两者都存在于纵深的树枝中时,它们就不能很好地工作。
e.q.菜单中的树
• Page 1
• Category 1
• Page 2
• Page 2在管理实层次结构中
• Category 1 > • Post 1
·在这种情况下,如果我在“类别1”中,它是菜单树中的父类,“第1页”,有类“当前菜单-祖先当前菜单-父”
·如果我在“类别1”中的后1(前端),这一个有“当前-后祖先当前菜单-父母当前-后父母”。但“第一页”即使与岗位1没有直接联系,仍然是“1类”的父级。但它没有被标记为父母或祖先。
我试着用自定义的步行器,甚至过滤"nav_menu_css_class“来找到检查的方法,
如果当前的任何子代都是祖先,这也是祖先。我们必须检查菜单树或真正的管理树,类别或页面。
因为如果是2级,那也应该是祖先级1。
发布于 2012-10-10 16:29:58
据我所知,这是正确的行为,
设想一个场景,您有一个包含顶级项目的菜单,第A页和第B页,每个菜单的第1类都附加为子菜单项。
当查看Post Example X、附加到Category 1和Category 1在菜单中出现两次时,在不同的顶级项下,我们看到;
/*
- Page A = no ancestor class!
- Category 1 = current-menu-ancestor, current-menu-parent, current-post-parent
- Page B = no ancestor class!
- Category 1 = current-menu-ancestor, current-menu-parent, current-post-parent
*/如果您查看一个Post,我们将其命名为Post Example X,那么哪个顶级菜单项应该接收current-menu-ancestor类?
WordPress两者都不决定。最好不要假设用户的意图是什么,除非有不同的指定,否则,如果您有与该类关联的特殊样式,那么它将应用于所有顶级菜单项,并且不会导致意外的结果。
但如果你对我说,类别1只出现在A页的顶层菜单下,没有其他地方,这仍然不重要.看看这些场景。
当查看Post Example X时,附加到Category 1中,其中Post Example X不显示在与顶级Page A或任何其他顶级树相同的菜单树中;
/*
- Page A = no ancestor class, still!
- Category 1 = current-menu-ancestor, current-menu-parent, current-post-parent
- Page B = not related to post
- Category 2 = not related to post
*/当查看Post Example X,它也是,附加到Category 1或在同一棵树作为最高层的Page A,我们看到;
/*
- Page A = current-menu-ancestor
- Category 1 = current-menu-ancestor, current-menu-parent, current-post-ancestor, current-post-parent
- Post Example X = current-menu-item
- Page B = not related to post
- Category 2 = not related to post
*/当查看Post Example X,这也是,附加到Category 1或在同一棵树作为顶级Page A,但其中Category 1也出现在Page B之下,但本身并不包含我们的帖子,我们看到;
/*
- Page A = current-menu-ancestor
- Category 1 = current-menu-ancestor, current-menu-parent, current-post-ancestor, current-post-parent
- Post Example X = current-menu-item
- Page B = not related to post
- Category = current-menu-ancestor, current-menu-parent, current-post-parent
*/我写这篇文章是为了给出一个大致的概念,它是如何工作的,接下来我将看一下nav_menu_css_class和wp_get_nav_menu_items的过滤器。
在菜单处理过程的逻辑背后,我的理解有点模糊,在此期间,可能会有其他人参与进来并提供帮助。
https://wordpress.stackexchange.com/questions/67760
复制相似问题