Magento - Output Layered Attribute Link in Product page
I've created attributes that I use successfully in the layered navigation of Magento.
Those attributes get output in the additional data section of the product page, however, attributes used in layered navigation don't appear as links. They're in plain text.
Simple example, I sell CDs, I have an artist attribute. I want to be able to click on the artist name, from the product page additional data section, to access the layered navigation results page that displays CDs only where this artist appears. Logic from a user point of view.
In other words, I want to get the layered navigation link from an attribute, in the product page.
Here’s what I find in catalog/product/view/attributes.html:
<?php foreach ($_additional as $_data): ?>
<?php echo $this->htmlEscape($this->__($_data['label'])) ?>
<?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?>
<?php endforeach; ?>
And here's the layered navigation loop:
<?php foreach ($this->getItems() as $_item): ?>
<?php if ($_item->getCount() > 0): ?>
<a href="<?php echo $this->urlEscape($_item->getUrl()) ?>"><?php echo $_item->getLabel() ?></a>
<?php else: echo $_item->getLabel() ?>
开发者_开发百科<?php endif; ?>
<?php endforeach ?>
Thanks much for your help.
If you enter the Artist name as text you can easily integrate it with the Advanced Search like this in catalog/product/view/attributes.html:
<?php if ($_data['label'] == "Artist"): ?>
<a href="/catalogsearch/advanced/result/?artist=<?php echo $_data['value']; ?>">
<?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></a>
<?php else: ?>
<?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?>
<?php endif; ?>
Let me know if this is what you meant :)
EDIT: Also not that this method only works if you enable your attribute for use in teh advanced search.
精彩评论