在 Opencart 的两列中按 odd/even 拆分属性组

Split attribute groups by odd/even in two columns in Opencart

我想用 dl 列表将大属性 table 拆分为两个单独的列。 Opencart 版本 2.2.0.0

现在的代码是(在/view/theme/default/template/product/product.tpl):

<?php if ($attribute_groups) { ?>
    <div class="tab-pane tab-content <?php if ($is_active) { echo 'active'; $is_active = false; } ;?>" id="tab-specification">
      <dl>
        <?php foreach ($attribute_groups as $attribute_group) { ?>
          <p><strong><?php echo $attribute_group['name']; ?></strong></p>
          <?php foreach ($attribute_group['attribute'] as $attribute) { ?>
          <dt><?php echo $attribute['name']; ?></dt>
          <dd><?php echo $attribute['text']; ?></dd>
          <?php } ?>
        <?php } ?>
      </dl>
    </div>
<?php } ?>

有什么想法吗? 提前致谢。

您可以将数组拆分为 2 个并使用 foreach 遍历它们。

How can i take an array, divide it by two and create two lists?

<?php if ($attribute_groups) {
    $firsthalf = array_slice($attribute_groups, 0, $len / 2);
    $secondhalf = array_slice($attribute_groups, $len / 2);
?>
    <div class="tab-pane tab-content <?php if ($is_active) { echo 'active'; $is_active = false; } ;?>" id="tab-specification">
      <dl>
        <?php foreach ($firsthalf as $attribute_group) { ?>
          <p><strong><?php echo $attribute_group['name']; ?></strong></p>
          <?php foreach ($attribute_group['attribute'] as $attribute) { ?>
          <dt><?php echo $attribute['name']; ?></dt>
          <dd><?php echo $attribute['text']; ?></dd>
          <?php } ?>
        <?php } ?>
      </dl>
      <dl>
        <?php foreach ($secondhalf as $attribute_group) { ?>
          <p><strong><?php echo $attribute_group['name']; ?></strong></p>
          <?php foreach ($attribute_group['attribute'] as $attribute) { ?>
          <dt><?php echo $attribute['name']; ?></dt>
          <dd><?php echo $attribute['text']; ?></dd>
          <?php } ?>
        <?php } ?>
      </dl>
    </div>
<?php } ?>

可能还有 css 解决方案,但你用 php 标记了它,所以我想这对你来说会更好。