我在名为“主菜单”的管理面板中创建了wp菜单,然后我尝试在标题中检索它。我得到的物品却无法让孩子低于父母。
在我的HTML模板中,菜单结构如下:
<ul class="rd-navbar-nav">
<li class="active"><a href="./">Home</a> </li>
<li><a href="#">About us</a>
<li><a href="#">Products</a>
<ul class="rd-navbar-megamenu">
<li>
<ul class="rd-megamenu-list">
<li><a href="product-catalog.html">Product 1</a></li>
<li><a href="product-catalog.html">Product 1</a></li>
<li><a href="product-catalog.html">Product 1</a></li>
</ul>
</li>
</ul>
<li><a href="#features">Services</a>
<ul class="rd-navbar-megamenu">
<li>
<ul class="rd-megamenu-list">
<li><a href="classic-news.html">Service 1</a></li>
<li><a href="classic-news.html">Service 2</a></li>
<li><a href="classic-news.html">Service 3/a></li>
<li><a href="classic-news.html">Service 4</a></li>
</ul>
</li>
<li>
<ul class="rd-megamenu-list">
<li><a href="classic-news.html">Service 5</a></li>
<li><a href="classic-news.html">Service 6</a></li>
<li><a href="classic-news.html">Service 7</a></li>
<li><a href="classic-news.html">Service 8</a></li>
</ul>
</li>
<li>
<!--<p class="rd-megamenu-header">Samouklapajući limovi</p>-->
<ul class="rd-megamenu-list">
<li><a href="classic-news.html">Service 5</a></li>
<li><a href="classic-news.html">Service 6</a></li>
<li><a href="classic-news.html">Service 7</a></li>
<li><a href="classic-news.html">Service 8</a></li>
</ul>
</li>
</ul>
<li><a href="#">News</a>
<li><a href="careers.html">Careers</a></li>
<li><a href="contacts.html">Content</a></li>
</ul>
在header.php中的我在WP管理面板中创建的retreive菜单。它组织得很好,但我唯一的麻烦就是打印
,我想在下面创建新的一行块
<li> // Here I need to count how many times is printed, if more than 4 then I shoud create new row
<ul class="rd-megamenu-list">
<a href="<?php echo $link; ?>" class="title"><?php echo $title; ?></a>
</ul>
</li>
<ul class="rd-navbar-nav">
<?php
$count = 0;
$submenu = false;
foreach( $menuitems as $item ):
$link = $item->url;
$title = $item->title;
// 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; ?>" class="title">
<?php echo $title; ?>
</a>
<?php endif; ?>
<?php if ( $parent_id == $item->menu_item_parent ): ?>
<?php if ( !$submenu ): $submenu = true; ?>
<ul class="rd-navbar-megamenu">
<?php endif;?>
<li> // Here I need to count how many times is printed, if more than 4 then I shoud create new row
<ul class="rd-megamenu-list">
<a href="<?php echo $link; ?>" class="title"><?php echo $title; ?></a>
</ul>
</li>
<?php if ( $menuitems[ $count + 1 ]->menu_item_parent != $parent_id && $submenu ): ?>
</ul>
<?php $submenu = false; endif; ?>
<?php endif; ?>
<?php if ( $menuitems[ $count + 1 ]->menu_item_parent != $parent_id ): ?>
</li>
<?php $submenu = false; endif; ?>
任何建议都有帮助