Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Magento静态块未正确显示。_Php_Magento - Fatal编程技术网

Php Magento静态块未正确显示。

Php Magento静态块未正确显示。,php,magento,Php,Magento,我仅根据类别Id创建了几个静态块,试图显示不同的块 问题在于,有时显示块,而有时不显示 我猜代码有问题?或者磁电机显示静态块的方式不确定 代码: <?php <?php $_description = $this->getProduct()->getDescription(); ?> <?php if ($_description): ?> <div class="std"> <?php echo $thi

我仅根据类别Id创建了几个静态块,试图显示不同的块

  • 问题在于,有时显示块,而有时不显示

  • 我猜代码有问题?或者磁电机显示静态块的方式不确定

代码:

<?php

<?php $_description = $this->getProduct()->getDescription(); ?>
<?php if ($_description): ?>
    <div class="std">
        <?php echo $this->helper('catalog/output')->productAttribute($this->getProduct(), $_description, 'description') ?>
        <?php $category = Mage::getModel('catalog/layer')->getCurrentCategory();?>
<?php if($category->getId()==14): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==15): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==16): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==18): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==19): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==86): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==25): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==13): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==98): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information_fbyz')->toHtml();?>
<?php else: ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information_others')->toHtml();?>
<?php endif; ?>

    </div>
<?php endif; ?>


请解决我的问题。

如果您将此代码放入
产品视图页面
中,则无法正确获取产品页面中的当前类别。。 使用
Mage::registry(“当前_类别”)
代替
Mage::getModel('catalog/layer')->getCurrentCategory()

如果您直接进入类别,则可以获取当前类别id产品页面。然后,您可以获取当前产品类别id

    $categoryIds = Mage::registry('current_product')->getCategoryIds();
    if(Mage::registry("current_category"))
    {
    $category = Mage::getModel('catalog/category')
->load(Mage::registry("current_category")->getId());
    }elseif(is_array($categoryIds )){
        //multiple categories id of product. that way i was taken on list category
        $category = Mage::getModel('catalog/category')->load($categoryIds[0]);
    }
    elseif(!is_null($categoryIds)){
            $category = Mage::getModel('catalog/category')->load($categoryIds);

    }
    else{
        //no categoies
    }

您是否在“产品视图”页上对该代码进行了编码???在“产品视图”页上进行了编码试图显示有关该产品的其他信息时,您无法正确理解该代码。基于类别id或类别id的数组,我想从后端显示指定的静态块。任何基于我的分类id的小例子都会很有帮助!