开发者

Product name limit in magento

I need to limit the length of the 开发者_如何学Pythonproduct name on the front end.

I am using Magento 1.4.2, can anybody help?


It's work for me

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


You can do this in the template files... Assuming you want to limit the name on the product view page, copy app/design/frontend/base/default/template/catalog/product/view.phtml to your theme in e.g. app/design/frontend/interface/theme/template/catalog/product/view.phtml. In line 52, you have something like

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

You can change this in:

<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>

Please try to describe your question in more detail next time...

Hope this helps.


Try this one. hope it should be working

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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜