2017-01-17 77 views
0

我想用dl列表将两个单独的列中的大属性表拆分。 Opencart的版本2.2.0.0在Opencart的两列中按奇数/偶数拆分属性组

现在的代码是(在/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 } ?> 

任何想法? 在此先感谢。

回答

1

你可以将数组拆分为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标记,所以我想这将更好地为您。

+0

非常感谢! – Aaviya

相关问题