是否有任何自定义代码可用于创建没有插件的2列超级菜单。 请帮帮我
答案 0 :(得分:0)
您可以通过以下代码管理Mega菜单:
<?php
$menu_name = 'primary';
$locations = get_nav_menu_locations();
$menu = wp_get_nav_menu_object( $locations[ $menu_name ] );
$menuitems = wp_get_nav_menu_items( $menu->term_id, array( 'order' => 'DESC' ) );
?>
<ul class="nav">
<?php
$count = 0;
$submenu = true;
foreach( $menuitems as $item ):
// set up title and url
$title = $item->title;
$link = $item->url;
// item does not have a parent so menu_item_parent equals 0 (false)
if ( !$item->menu_item_parent ):
// save this id for later comparison with sub-menu items
$parent_id = $item->ID;
?>
<li>
<a href="<?php echo $link; ?>">
<span><?php echo $title; ?></span>
</a>
<?php endif; ?>
<?php if ( $parent_id == $item->menu_item_parent ): ?>
<?php if ( !$submenu ): $submenu = true; ?>
<div class="mega-menu sub-menu-columns">
<div class="mega-bg">
<div class="mega-mrg">
<div class="maga-half">
<ul>
<?php endif; ?>
<li><a href="<?php echo $link; ?>" class="title"><?php echo $title; ?></a></li>
<?php if ( $menuitems[ $count + 1 ]->menu_item_parent != $parent_id && $submenu ): ?>
</ul>
</div>
</div>
</div>
</div>
<?php $submenu = false; endif; ?>
<?php endif; ?>
<?php if (@$menuitems[ $count + 1 ]->menu_item_parent != $parent_id ): ?>
</li>
<?php $submenu = false; endif; ?>
<?php $count++; endforeach; ?>
</ul>
希望这对你有用。