2017-01-17 74 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

相關問題