1

i have a magento site and my all products name too long,that why on categories page design has been broken.I am new in magento,can anybody tell,who can tell me,who i will do

1
  • Where on the category page do you want the product name to be limited (truncated?)? In the product list? Everywhere? Aug 22, 2014 at 12:21

2 Answers 2

4

goto list.phtml in (yourpackage/yourtemplate/template/catalog/product)

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

to

<?php echo substr($_helper->productAttribute($_product, $_product->getName() , 'name'),0,520) ; ?>
3
  • Got error : Parse error: syntax error, unexpected '?' in /home/nflgeegn/public_html/app/design/frontend/ultimo/default/template/catalog/product/list.phtml on line 117 Aug 22, 2014 at 9:52
  • 1
    @LuckyDhillon. Try again with the new code. I edited the answer.
    – Marius
    Aug 22, 2014 at 10:47
  • still doesn't work.. nothing changes on the frontend Aug 24, 2014 at 12:21
2

you can edit your product list file

/app/designyourpackage/yourtheme/template/catalog/product/list.phtml


 <?php $prod_name = $_helper->productAttribute($_product, $_product->getName(), 'name'); ?>
                    <?php
                    $count_str = strlen($prod_name);
                    if ($count_str < 50) {
                        echo $prod_name;
                    } else {
                        $offset = 0;
                        $length = 51;   
                        $prod_name = html_entity_decode($prod_name);                     
                        echo htmlentities(mb_substr($prod_name,0,$length,'utf-8')). "...";;                        
                    }
                    ?>

if you don't have character encoding issue you can use php substr function as well.

hope this will sure help you

5
  • I added the above code in list.phtml changed the length= 10; but nothing changed. Aug 22, 2014 at 10:00
  • you can use substr function of php.
    – liyakat
    Aug 22, 2014 at 11:05
  • you edited correct file ? it should work. its working in my end. And also please change if condition as well if ($count_str < 10) {
    – liyakat
    Aug 22, 2014 at 11:27
  • still doesn't work .. Aug 24, 2014 at 12:24
  • you can use like <?php echo substr("Hello world",0,4); will print hello for detail see w3schools.com/php/func_string_substr.asp ?>
    – liyakat
    Aug 25, 2014 at 4:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.