簡體   English   中英

產品名稱限制在 magento

[英]Product name limit in magento

我需要限制前端產品名稱的長度。

我正在使用 Magento 1.4.2,有人可以幫忙嗎?

這對我有用

<?php $productName = $this->htmlEscape($_product->getName()); 
echo Mage::helper('core/string')->truncate($productName, $length = 50, $etc = '...', $remainder = '', $breakWords = true); ?>

您可以在模板文件中執行此操作...假設您要限制產品視圖頁面上的名稱,請將app/design/frontend/base/default/template/catalog/product/view.phtml到您的主題中,例如app/design/frontend/interface/theme/template/catalog/product/view.phtml 在第 52 行,你有類似的東西

<h1><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h1>

您可以在以下位置進行更改:

<h1>
    <?php
        // define the maximum length of the product name here
        $maxLength = 10;
        $productName = $_helper->productAttribute($_product, $_product->getName(), 'name');
        echo substr($productName, 0, $maxLength);
    ?>
</h1>

下次請嘗試更詳細地描述您的問題...

希望這可以幫助。

試試這個。 希望它應該工作

$shortDescription = $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description'); 

echo Mage::helper('core/string')->truncate($shortDescription, $length = 50, $etc = '...', $remainder = '', $breakWords = true);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM