We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hi, what is the code for display menu in frontend ?
The text was updated successfully, but these errors were encountered:
Hey!
I had the same question. So, for the others who ask it too, here is my simple block created :
<?php // Create class attribute allowing for custom "className" and "align" values. $className = 'menu-block'; if ( ! empty( $block['className'] ) ) { $className .= ' ' . $block['className']; } if ( ! empty( $block['align'] ) ) { $className .= ' align' . $block['align']; } $menuId = get_field( 'menu' ) ?: null; function generateMenuMarkup( $menu_id ) { if (!is_string($menu_id)) return 'An error has occurs on generation. Excepted menu ID as string type, given (' . gettype($menu_id) . ') ' . $menu_id; $menuData = wp_get_nav_menu_items( $menu_id ); $menuMarkup = '<ul id="navbar-menu" class="menu">'; foreach ( $menuData as $menuElement ) { if ( $menuElement->menu_item_parent !== '0' ) { return 'This bloc "menu-block" doesn\'t support submenu !'; } $menuMarkup .= '<li class="menu-item' . ($menuElement->url === get_permalink(get_the_ID()) ? ' current-menu-item' : '') . '">' . '<a href="' . $menuElement->url . '">' . $menuElement->title . '</a>' . '</li>'; } $menuMarkup .= '</ul>'; return $menuMarkup; } ?> <div class="<?php echo esc_attr( $className ); ?>"> <?php echo generateMenuMarkup( $menuId ) ?> </div>
Sorry, something went wrong.
No branches or pull requests
hi,
what is the code for display menu in frontend ?
The text was updated successfully, but these errors were encountered: