How to add attributes to product list – grid in category

How can i add my attributes to product list-grid in category?
i’ve try with this guide but don’t work

http://www.magentocommerce.com/wiki/…date_templates

tank’s a lot

6 answers

Profile photo of thangnn1510 0.00 $tone December 27, 2010
Public

Hi Altravista!

Regarding your question, after you add a new attribute and set value for each product. You could add this code:

PHP Code:

 <?php 
$_product
=Mage::getModel("catalog/product")->load($_product->getId());
echo 
$_product->getTestAttribute(); 
?>


To about between line 96 and 97 and between line 59 and 60 of app/design/frontend/default/jm_lime/template/catalog/product/list.phtml.

Hope this help you and have a good week.

#1
Profile photo of Marco Boatti 0.00 $tone December 27, 2010
Public

i’ve try but don’t work
-- try also whit attribute name <?php
$_product=Mage::getModel("catalog/product")->load($_product->getId());
echo $_product->getTestAttribute(‘sottotitolo’);
?>
this is my code:

<?php $_productCollection=$this->getLoadedProductCollection() ?>
<?php if(!$_productCollection->count()): ?>
<p class="note-msg"><?php echo $this->__(‘There are no products matching the selection.’) ?></p>
<?php else: ?>
<div class="category-products">
<?php echo $this->getToolbarHtml() ?>
<?php // List mode ?>
<?php if($this->getMode()!=’grid’): ?>
<?php $_iterator = 0; ?>
<ol class="products-list" id="products-list">
<?php foreach ($_productCollection as $_product): ?>
<li class="item<?php if( ++$_iterator == sizeof($_productCollection) ): ?> last<?php endif; ?>">
<?php // Product Image ?>
<div class="product-image">
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, ‘small_image’)) ?>" ><img src="<?php echo $this->helper(‘catalog/image’)->init($_product, ‘small_image’)->resize(170,130); ?>" width="170" height="130" alt="<?php echo $this->htmlEscape($this->getImageLabel($_product, ‘small_image’)) ?>" /></a>
<div class="price-form">
<?php echo $this->getPriceHtml($_product, true) ?>
<?php if($_product->isSaleable()): ?>
<p><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></p>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__(‘Out of stock’) ?></span></p>
<?php endif; ?>
</div>
</div>
<?php // Product description ?>
<div class="product-shop">
<div class="f-fix">
<h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><?php echo $this->htmlEscape($_product->getName())?></a></h2>
<?php
$_product=Mage::getModel("catalog/product")->load($_product->getId());
echo $_product->getTestAttribute();
?>
<?php if($_product->getRatingSummary()): ?>
<?php echo $this->getReviewsSummaryHtml($_product) ?>
<?php endif; ?>
<div class="desc std">
<?php echo nl2br($this->htmlEscape($_product->getShortDescription())) ?>
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>" class="link-more"><?php echo $this->__(‘Learn More’) ?></a>
</div>
<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>
</div>
</li>
<?php endforeach; ?>
</ol>
<script type="text/javascript">decorateList(‘products-list’, ‘none-recursive’)</script>

<?php else: ?>

<?php // Grid Mode ?>

<?php $_collectionSize = $_productCollection->count() ?>
<?php $_columnCount = $this->getColumnCount()-1; ?>

<?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->htmlEscape($this->getImageLabel($_product, ‘small_image’)) ?>" class="product-image"><img src="<?php echo $this->helper(‘catalog/image’)->init($_product, ‘small_image’)->resize(170,130); ?>" width="170" height="130" alt="<?php echo $this->htmlEscape($this->getImageLabel($_product, ‘small_image’)) ?>" /></a>
<h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><?php echo $this->htmlEscape($_product->getName()) ?></a></h2>
<?php
$_product=Mage::getModel("catalog/product")->load($_product->getId());
echo $_product->getTestAttribute();
?>
<?php if($_product->getRatingSummary()): ?>
<?php echo $this->getReviewsSummaryHtml($_product, ‘short’) ?>
<?php endif; ?>
<?php echo $this->getPriceHtml($_product, true) ?>
<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: ?>
<p 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==0 || $i==$_collectionSize): ?>
</ul>
<div class="ja-dot">&nbsp;</div>
<?php endif ?>
<?php endforeach ?>
<script type="text/javascript">decorateGeneric($$(‘ul.products-grid’), [‘odd’,’even’,’first’,’last’])</script>
<?php endif; ?>

<div class="toolbar-bottom">
<?php echo $this->getToolbarHtml() ?>
</div>
</div>
<?php endif; ?>

#2
Profile photo of thangnn1510 0.00 $tone December 29, 2010
Public

Dear Altravista!

if the attribute code of your attribute is test_attribute you should get it by:

PHP Code:

 <?php 
$_product
=Mage::getModel("catalog/product")->load($_product->getId());
echo 
$_product->getTestAttribute(); 
?>


in your case it is "sottotitolo" so you should change $_product->getTestAttribute(); to $_product->getSottotiolo();

Hope this helps.

#5

This question is now closed

Written By

Comments