多嚿魚教室

Opencart優化技巧

我在Opencart後台輸入Product的attribute時有換行,但店面顯示的卻沒有換行,怎麼辦?
在Opencart後台輸入Product的attribute時有換行。
店面顯示的Product attribute沒有換行。
Finding Solution
Opencart後台是用<textarea>HTML標籤來裝載你輸入的Product attribute,而HTML會無視textarea的換行符\n,所以店面顯示的Product attribute沒有換行。
解決辦法:將\n轉為HTML換行標籤<br />;或用不會忽略\n的HTML標籤來裝載Product attribute。
我們熱心幫助無叉用的人
以下方法適用於Opencart v1.5.1.3
方法1——PHP修正:
  1. 編輯[catalog/model/catalog/product.php]
  2. 搜尋以下程式碼:
      foreach ($product_attribute_query->rows as $product_attribute) {
        $product_attribute_data[] = array(
          'attribute_id' => $product_attribute['attribute_id'],
          'name'         => $product_attribute['name'],
          'text'         => $product_attribute['text']       
        );
      }
  3. $product_attribute['text']更改為nl2br($product_attribute['text'])
nl2br()是PHP函數,會在\n之前插入HTML換行標籤<br />
方法2——HTML修正:
  1. 編輯[catalog/view/theme/default/template/product/product.tpl]
  2. 搜尋以下程式碼:
    <?php foreach ($attribute_group['attribute'] as $attribute) { ?>
    <tr>
      <td><?php echo $attribute['name']; ?></td>
      <td><?php echo $attribute['text']; ?></td>
    </tr>
    <?php } ?>
  3. <td><?php echo $attribute['text']; ?></td>修改為<td><pre><?php echo $attribute['text']; ?></pre></td>
<pre>會保留文本中的空格和換行符號。
方法3——CSS修正:
  1. 編輯[catalog/view/theme/default/stylesheet/stylesheet.css]
  2. 到最後一行加入以下程式碼:
    .attribute tbody tr td { white-space: pre-wrap; }
    
white-space: pre-wrap;會保留其套用文本中的空格和換行符號。

0 comments:

Post a Comment