简体   繁体   English

我正在尝试通过view.phtml将相关类别链接添加到Magento中的产品页面

[英]I am trying to add related categories link to a product page in Magento via view.phtml

The functionality I am trying to add is due to the fact that there are links floating around there that could potentially land on a page that the product is out of stock, discontinued, etc. These types products are automatically set to a "catalog" view and "Not Visible Individually." 我要添加的功能是由于以下事实:周围有链接浮动,这些链接可能会在产品缺货,停产等页面上着陆。这些类型的产品会自动设置为“目录”视图和“不可见”。 we have overcome the fact they are no longer just getting a 404 error page, but now I would like to add the option to view other products from that same category? 我们已经克服了一个事实,那就是它们不再仅显示404错误页面,但是现在我想添加一个选项来查看同一类别的其他产品?

I have this: 我有这个:

<?php $count =0; ?>
<?php $categories = $_product->getCategoryIds();?>
<?php foreach($categories as $k => $_category_id): ?>
<?php $_category = Mage::getModel('catalog/category')->load($_category_id) ?>

  <li> <a href="<?php echo $_category->getUrl() ?>" title="<?php echo $_category->getName() ?>"><?php echo $_category->getName() ?></a> </li>               
                <?php $count++; 
                 if($count== 10) break; ?>
                <?php endforeach; ?>

It pulls back the categories correctly, but there are categories that I need to filter out and I can't figure out how to do that? 它可以正确地拉回类别,但是有些类别需要过滤掉,我不知道该怎么做? Any help would be GREATLY appreciated? 任何帮助将不胜感激?

One way to do this, is to filter by id's: 一种方法是按ID进行过滤:

<?php 
foreach($categories as $k => $_category_id):

    if($_category_id == $idToFilter):
        continue;
    else:
    // show the category etc.
    endif;
endforeach;
?> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM