简体   繁体   English

产品名称限制在 magento

[英]Product name limit in magento

I need to limit the length of the product name on the front end.我需要限制前端产品名称的长度。

I am using Magento 1.4.2, can anybody help?我正在使用 Magento 1.4.2,有人可以帮忙吗?

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 eg app/design/frontend/interface/theme/template/catalog/product/view.phtml .您可以在模板文件中执行此操作...假设您要限制产品视图页面上的名称,请将app/design/frontend/base/default/template/catalog/product/view.phtml到您的主题中,例如app/design/frontend/interface/theme/template/catalog/product/view.phtml In line 52, you have something like在第 52 行,你有类似的东西

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM