导航块是用于容纳允许访客浏览您网站的各类块的容器块。另见“导航链接”块和“导航子菜单”块。
CSS 类
导航块的结构性 CSS 针对多种菜单项的通用类名,包括由页面列表块自动生成的那些。以下是一些值得注意的类名及其用途:
.wp-block-navigation__submenu-container应用于主菜单项的子菜单。.wp-block-navigation-item应用于每个菜单项。.wp-block-navigation-item__content应用于菜单项内的链接。.wp-block-navigation-item__label应用于围绕菜单项文本标签的最内层容器。.wp-block-navigation-item__description应用于围绕菜单项描述的最内层容器。.wp-block-navigation__submenu-icon应用于子菜单指示器(倒三角)。
允许访客浏览您网站的块集合。
- Name:
core/navigation - Category: theme
- API Version: 3
- Block Type: Hybrid(静态保存 + 服务器增强)
- Keywords:
menu,navigation,links
块关系
允许的内部块:
– core/navigation-link
– core/search
– core/social-links
– core/page-list
– core/spacer
– core/home-link
– core/icon
– core/site-title
– core/site-logo
– core/navigation-submenu
– core/loginout
– core/buttons
属性
通过 block.json 中的 attributes 属性定义。
| 属性 | 类型 | 默认值 | 描述 |
|---|---|---|---|
ref | number | — | — |
textColor | string | — | — |
customTextColor | string | — | — |
rgbTextColor | string | — | — |
backgroundColor | string | — | — |
customBackgroundColor | string | — | — |
rgbBackgroundColor | string | — | — |
showSubmenuIcon | boolean | true | — |
submenuVisibility | string | "hover" | 枚举:hover, click, always |
overlayMenu | string | "mobile" | — |
overlay | string | — | — |
icon | string | "handle" | — |
hasIcon | boolean | true | — |
__unstableLocation | string | — | — |
overlayBackgroundColor | string | — | — |
customOverlayBackgroundColor | string | — | — |
overlayTextColor | string | — | — |
customOverlayTextColor | string | — | — |
maxNestingLevel | number | 5 | — |
templateLock | string \| boolean | — | 枚举:all, insert, contentOnly, false |
支持
通过 block.json 中的 supports 属性定义。
anchor:truealign:"wide","full"ariaLabel:truecontentRole:truehtml:falseinserter:truetypography:fontSize:truelineHeight:true
spacing:blockGap:trueunits:["px","em","rem","vh","vw"]
layout:allowSwitching:falseallowInheriting:falseallowVerticalAlignment:falseallowSizingOnChildren:truedefault:{"type":"flex"}
interactivity:truerenaming:false
上下文
通过 block.json 中的 usesContext 和 providesContext 属性定义。
提供上下文:
textColor→ 属性textColorcustomTextColor→ 属性customTextColorbackgroundColor→ 属性backgroundColorcustomBackgroundColor→ 属性customBackgroundColoroverlayTextColor→ 属性overlayTextColorcustomOverlayTextColor→ 属性customOverlayTextColoroverlayBackgroundColor→ 属性overlayBackgroundColorcustomOverlayBackgroundColor→ 属性customOverlayBackgroundColorfontSize→ 属性fontSizecustomFontSize→ 属性customFontSizeshowSubmenuIcon→ 属性showSubmenuIconsubmenuVisibility→ 属性submenuVisibilityopenSubmenusOnClick→ 属性openSubmenusOnClickstyle→ 属性stylemaxNestingLevel→ 属性maxNestingLevel
区块标记
这是一个 混合区块。它保存服务器在渲染过程中可能进行增强的静态标记。
<!-- wp:navigation -->
<!-- /wp:navigation -->
来源
- block.json (参考)
- 源代码目录 — 浏览
edit和save源文件、index.php等。