specific menu in custom block theme, with atypic style
-
I’m learning to create WordPress block themes.
In a block theme I would like to display a specific menu that I defined in Appearance->Menus in dashboard (enabled menus throughadd_theme_support('menus');
infunctions.php
, and with kinda specific layout that is not shipped with any theme on WP that I know.Atm I don’t even understand how to view items from specific menu, only block
<!-- wp:navigation /-->,
which views links to all parent pages with submenus, not only those that were specified in any specific menu in Appearance->Menus.
How can I display a specific menu through blocks? Anything I found waswp_nav_menu()
for classic themes. Not sure if this is what I’m searching for, but it could be a good start probably. Is there some alternative to this for block themes?
I tried<!-- wp:navigation {"menu":"<menu name here>"} /-->
, but it just displayed the block as html instead of navigation menu.Now the more complex part: is there any way to fetch list of pages from specific menu and process it with js, or even with php to be compliant with block theme rules? In classic theme I could fetch pages using either
get_pages()
to fetch all pages, or maybe usingwp_get_nav_menu_items()
with some other function to get title from page id. That second thing is just an assumption – I didn’t do the second case yet. Afterwards I could process those fetched pages with php and put them anywhere on the site.
I would like to have one kinda atypic style – menu bar with parent items, and when a parent item is hovered with mouse, whole menu would resize, so it would fit a submenu under parent.Let’s say menu would look like this:
And after hovering, whole menu bar will grow in height like this:
In classic theme I managed to do it with menu blocks, each consisting from parent item holder (the one up), and submenu holder (the items right under the parent item when hovered), and processed it with php – what item to which box.
How can I achieve that? What would be the most correct way of doing this in WP block theme?
I am experienced in HTML/CSS/JS/PHP, but new to WPThanks in advance
- The topic ‘specific menu in custom block theme, with atypic style’ is closed to new replies.