Php 在门店类别列表中显示更多选项

Php 在门店类别列表中显示更多选项,php,foreach,Php,Foreach,如何在存档列表页面上仅显示6个类别,然后在选择的类别超过6个时显示更多类别的按钮 <?php $terms = get_the_terms($post->ID, 'store_categories'); if ($terms && !is_wp_error($terms)): $store = array(); foreach ($terms as $term) { $store[] = $term->name; }

如何在存档列表页面上仅显示6个类别,然后在选择的类别超过6个时显示更多类别的按钮

<?php
$terms = get_the_terms($post->ID, 'store_categories');
if ($terms && !is_wp_error($terms)):
    $store = array();
    foreach ($terms as $term) {
        $store[] = $term->name;
    }
    $store_category = join(" | ", $store);
?>
      <h3 id="storeCat">
            <?php
    $url = site_url();
    foreach ($terms as $term) {
        $linklist .= "<a href='" . $url . "/store_categories/" . $term->slug . "' target='_blank'>" . $term->name . "</a>" . "&nbsp; ";
    }
        echo $linklist;
?>
      </h3>
        <?php
endif;
?>


在一个
中输出前6个,然后在另一个隐藏的
中输出其余的,并在按钮上显示一些javascript?我将重新表述我的问题。我如何只打印这个循环中的6,然后在下一行显示其余的按钮?