我创建了以下内容,以允许根据类别 ID 在产品页面上显示不同的静态 CMS 块。
<?php 
    $_category_detail=Mage::registry('current_category'); //Get the current category id
    $product = Mage::getModel('catalog/product')->load($product_id);   //Get the current category id
    $category = Mage::getModel('catalog/layer')->getCurrentCategory(); //Get the current category id
    ?>
<?php if($category->getId()==23): ?>
    <div id="sizingmap">
        <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('sizespecpantsslim')->toHtml(); ?>
    </div>
<?php endif;?>  
<?php if($category->getId()==10): ?>
    <div id="sizingmap">
        <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('sizespecjacket')->toHtml(); ?>
    </div>
<?php endif;?>
类别部分的一切都很好,尽管我想根据同一类别中的产品 ID 显示不同的块。
例如(这显然是不正确的):
<?php if($category->getId()==23) "AND the product id are "372,363,354,349,344": ?>
<div id="sizingmap">
    <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('sizespecpantsslim')->toHtml(); ?>
</div>
else // if they are not the mentioned product id's 
<div id="sizingmap">
    <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('sizespecpantsstd')->toHtml(); ?>
</div>