For use in the .phtml files:
Page path:
<?php echo $this->getUrl('mypage'); ?>
Image path:
<?php echo $this->getSkinUrl('images/button.gif'); ?>
Product link:
<?php echo $this->getProductData()->getProductUrl(); ?>
Product name:
<?php echo $this->htmlEscape($this->getProductData()->getName()); ?>
Display all of a product’s categories:
<?php
$categories = $_product->getCategoryIds();
foreach($categories as $k => $_category_id):
$_category = Mage::getModel('catalog/category')->load($_category_id);
?>
<a href="<?php echo $_category->getUrl() ?>"><?php echo $_category->getName() ?>
<?php endforeach; ?>
Use a static block in a template file:
<?php echo $this->getLayout()->createBlock('cms/block')->
setBlockId('YOURBLOCKID')->toHtml(); ?>
Test for a product attribute:
<?php
if ($this->product['attributename'] == "attributevalue") {
// Add your stuff here
}
?>
Test if in category
<?php
if ($this->getCurrentCategory()->getName() == "My Category") {
//Add some stuff
}
?>
Call an attribute on the product list page:
<?php
if ($_product->getData('attributename')):
$_staff_pick= $_product->getResource()->getAttribute ('attributename')->getFrontend()->getValue($_product);
if ($_attributename == "Yes"){
// attribute
}
endif;
?>
More functions:
$this->getCurrentCategory()->getImageUrl();
$this->getCurrentCategory()->getDescription();
$this->IsTopCategory();
$this->getProductListHtml();
$this->getCmsBlockHtml();
For use from within a Magento CMS page:
Call a static block from within a content area
{{block type="cms/block" block_id="your_block_identifier" template="cms/content.phtml"}}
Image path from within CMS:
{{skin url="images/logo.gif"}}
Other product attributes:
Using $this->product['attributename'] syntax:
(Values for these attributes are here just as examples.)
[store_id] => 1
[entity_id] => 3
[entity_type_id] => 4
[attribute_set_id] => 4
[type_id] => simple
[sku] => 2281
[category_ids] => 2,15,17,23,24
[created_at] => 2008-09-09 16:24:03
[updated_at] => 2008-09-15 22:47:51
[has_options] => 0
[name] => ProductName
[url_key] => productname
[gift_message_available] => 2
[meta_title] =>
[meta_description] =>
[image] => /p/r/product_productname.gif
[small_image] => /p/r/product_productname.gif
[thumbnail] => /p/r/product_productname.gif
[custom_design] => default/yourthemefolder
[options_container] => container2
[url_path] => productname.html
[status] => 1
[visibility] => 4
[tax_class_id] => 0
[weight] => 1.0000
[price] => 37.9900
[description] =>
[short_description] =>
[meta_keyword] =>
[custom_layout_update] =>
[media_gallery] => Array
[tier_price] => Array
[stock_item] =>
Advertisement