我有一个返回的子类别列表。我只能访问模板显示而不能访问 MySQL 查询,所以不,我不能限制查询。
现在所有结果都返回了。我想将列表限制为 5 个,如果结果超过 5 个,则添加一个“更多”链接。
我知道我做错了,因为我认为count实际上与以下内容无关foreach:
<ul class="sub-categories">
    <?php
    while (count($category->getChildren()) <= 5) { // line I added for while loop
        foreach ($category->getChildren() as $child) {
            if (!$child->totalItemCount())
                continue;
            $link = $this->app->route->category($child);
            $item_count = ($this->params->get('template.show_sub_categories_item_count')) ? ' <span>('.$child->totalItemCount().')</span>' : '';
                echo '<li><a href="'.$link.'" title="'.$child->name.'">'.$child->name.'</a>'.$item_count.'</li>';
        }
    } // line I added for while loop
    ?>
</ul>