简体   繁体   中英

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?

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:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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