Magento – Show a Static Block in the product view.phtml based on category

Edit view.phtml and put this code in:

getCategoryIds(); ?>
$_category_id): ?>
load($_category_id) ?>
getName() ?>

if ($_category->getName() == ‘YourCategoryName’) {echo $this->getLayout()->createBlock(‘cms/block’)->setBlockId(‘yourstaticblockname’)->toHtml();}
else {echo $this->getLayout()->createBlock(‘cms/block’)->setBlockId(‘blank’)->toHtml();}
?>

Magento – Getting the paths

To Retrieve URL path in STATIC BLOCK

To get SKIN URL

{{skin url=’images/sampleimage.jpg ‘}}

To get Media URL

{{media url=’/sampleimage.jpg’}}

To get Store URL

{{store url=’mypage.html’}}

To get Base URL

{{base url=’yourstore/mypage.html’}}

To Retrieve URL path in PHTML
Note: In editing PHTML don’t forget to enclode the following code with PHP tag

Not secure Skin URL

getSkinUrl(‘images/sampleimage.jpg’) ?>

Secure Skin URL

getSkinUrl(‘images/ sampleimage.gif’, array(‘_secure’=>true)) ?>

Get Current URL

$current_url = Mage::helper(‘core/url’)->getCurrentUrl();

Get Home URL

$home_url = Mage::helper(‘core/url’)->getHomeUrl();