我对foreach拆分有问题。我需要用子菜单包装那些项目,更像是10来显示更多div。
如何完全包装所有其他物品?
<ul>
<li><a href="#">Visas preces</a></li>
<?php
$childid = get_product_top_level_category ( get_the_ID());
$args = array(
'taxonomy' => 'product_cat',
'parent' => $childid
);
$terms = get_terms( $args );
$i = 1;
foreach( $terms as $term ) {
echo '<li><a href="'.get_term_link( $term->slug, 'product_cat' ).'">'. $term->name .'</a></li>';
if ($i == 10)
{ ?></li>
<li class="more dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">Vairāk</a>
<div class="dropdown-menu">
<ul>
<?php }
$i++;
}
?>
</ul>
</div>
</li>
</ul>
答案 0 :(得分:0)
如果条件
,则可以在else案例中为所有其他索引添加逻辑if ($t < "20") {
echo "Have a good day!";
} else {
echo "Have a good night!";
}