Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

How to limit the product name in grid view
 
Calli
Jr. Member
 
Total Posts:  2
Joined:  2012-11-03
 

I notice some of the product name is too long that end up with 3 rows while some prodcut name only 1 row. this causes the price align in differnt levels, makes the site messy. I want the product name only show 2 rows and hide extra words.

I tried to add this code below in app/design/frontend/base/default/template/catalog/product/view.phtml line 50. but it didn’t work. (my magento version is 1.7.2)

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

anyone know how to fix this? thanks for your help in advance.

Calli

 
Magento Community Magento Community
Magento Community
Magento Community
 
magestore_1
Mentor
 
Avatar
Total Posts:  1015
Joined:  2009-08-07
Viet Nam
 

Hello,
I have checked your code in our demo site and see that it’s working well. I think your code didn’t work because you added the code into incorrect file. If you want to limit the product name in grid view, you need to add the code into the file app/design/frontend/base/default/template/catalog/product/list.phtml, line 96 instead of app/design/frontend/base/default/template/catalog/product/view.phtml.
Hope you will succeed!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Calli
Jr. Member
 
Total Posts:  2
Joined:  2012-11-03
 

Hi,

thanks for your help! I tired to add to the list.phtml file but it didn’t work for me. here is the file code. as you can see i added the code in line 96 and cancelled the old code.

<?php // Grid Mode ?>

    
<?php $_collectionSize $_productCollection->count() ?>
    <?php $_columnCount 
$this->getColumnCount(); ?>
    <?php $i
=0; foreach ($_productCollection as $_product): ?>
        <?php 
if ($i++%$_columnCount==0): ?>
        
<ul class="products-grid">
        
<?php endif ?>
            
<li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
                <
a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>
                <
h1><?php $maxLength 10$productName $_helper->productAttribute($_product$_product->getName(), 'name'); echo substr($productName0$maxLength); ?></h1>
                <!--<
h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $_helper->productAttribute($_product$_product->getName(), 'name'?></a></h2>-->
                
<?php if($_product->getRatingSummary()): ?>
                <?php 
echo $this->getReviewsSummaryHtml($_product'short'?>
                <?php 
endif; ?>
                <?php 
echo $this->getPriceHtml($_producttrue?>
                
<div class="actions">
                    
<?php if($_product->isSaleable()): ?>
                        
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart'?></span></span></button>
                    
<?php else: ?>
                        
<class="availability out-of-stock"><span><?php echo $this->__('Out of stock'?></span></p>
                    
<?php endif; ?>
                    
<ul class="add-to-links">
                        
<?php if ($this->helper('wishlist')->isAllow()) : ?>
                            
<li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist'?></a></li>
                        
<?php endif; ?>
                        <?php 
if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
                            
<li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare'?></a></li>
                        
<?php endif; ?>
                    
</ul>
                </
div>
            </
li>
        
<?php if ($i%$_columnCount==|| $i==$_collectionSize): ?>
        
</ul>
        
<?php endif ?>
        <?php 
endforeach ?>
        
<script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>
    <?php 
endif; ?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
ictconnection
Jr. Member
 
Total Posts:  17
Joined:  2010-11-20
 

Just what i was looking for thanks,

I have altered the code so it remains a link with the title tag.

<h2 class=\"product-name\"><a href=\"<?php echo $_product->getProductUrl() ?>\” title=\"<?php echo $this->stripTags($_product->getName(), null, true) ?>\"><?php $maxLength = 30; $productName = $_helper->productAttribute($_product, $_product->getName(), \'name\'); echo substr($productName, 0, $maxLength); ?></a></h2>

but i would also like to add ... to the end of the echo.

any ideas ?

Regards,

 
Magento Community Magento Community
Magento Community
Magento Community
 
ictconnection
Jr. Member
 
Total Posts:  17
Joined:  2010-11-20
 

I just added <?php echo $this->__(\\\\\\\'...\\\\\\\') ?> and it works.

<h2 class=\\\\\\\"product-name\\\\\\\"><a href=\\\\\\\"<?php echo $_product->getProductUrl() ?>\\\\\\\” title=\\\\\\\"<?php echo $this->stripTags($_product->getName(), null, true) ?>\\\\\\\"><?php $maxLength = 30; $productName = $_helper->productAttribute($_product, $_product->getName(), \\\\\\\'name\\\\\\\'); echo substr($productName, 0, $maxLength); ?><?php echo $this->__(\\\\\\\'...\\\\\\\') ?></a></h2>

or is there a better way ?

Regards,

 
Magento Community Magento Community
Magento Community
Magento Community
 
Sal_C
Jr. Member
 
Total Posts:  9
Joined:  2013-11-15
 

just used this. Thank you. works.

 
Magento Community Magento Community
Magento Community
Magento Community
 
christinavick
Guru
 
Total Posts:  355
Joined:  2013-11-13
 

Hello,

You can also have a look this thread [url=http://stackoverflow.com/questions/6733741/product-name-limit-in-magento]http://stackoverflow.com/questions/6733741/product-name-limit-in-magento[/url]

Thanks

iLoveMage

 
Magento Community Magento Community
Magento Community
Magento Community
 
pra01raj
Jr. Member
 
Total Posts:  1
Joined:  2013-03-21
 

Hi I am facing the same issue, I put the code many time but have not get it resolved my code is :

<h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>” title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $maxLength = 10; $productName = $_helper->productAttribute($_product, $_product->getName(), 'name'); echo substr($productName, 0, $maxLength); ?></a></h2>

On line no. 96

but it could not help

 
Magento Community Magento Community
Magento Community
Magento Community
 
llourenzo
Jr. Member
 
Total Posts:  9
Joined:  2011-07-15
 

great post thanks

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top