我想從我擁有的隨機菜單中排除一個特定類別。我已經搜索了答案,並在這裏找到了一些潛在的解決方案,但是他們都沒有工作。Magento:從下拉菜單中排除特定類別
這是我目前有:
<?php
$catID = $this->category_id;
$catName = $this->category_name;
$catType = $this->category_type;
$category = Mage::getModel('catalog/category')->load($catID);
$categories = $category->getCollection()
->addAttributeToSelect(array('name', 'thumbnail', 'description'))
->addAttributeToFilter('is_active', 1)
->addIdFilter($category->getChildren());
$catIdEx = 38;
$categories->getSelect()->join(array('cats' => 'catalog_category_product'), 'cats.product_id = e.entity_id');
$categories->getSelect()->where('cats.category_id', array('neq' => $catIdEx));
$categories->getSelect()->group(array('e.entity_id'));
$categories->getSelect()->order('RAND()');
$categories->getSelect()->limit(1);
?>
<?php foreach ($categories as $category): ?>
<div>
<a href="<?php echo $category->getUrl(); ?>">
<img src="<?php echo Mage::getBaseUrl('media') . 'catalog' . DS . 'category' . DS . $category->getThumbnail() ?>" alt="<?php echo $this->htmlEscape($category->getName()) ?>" class="boxedimage" />
</a>
<br />
<h3>Spotlight <?php echo $catName ?></h3>
<?php
$sdesc = $category->getDescription();
$sdesc = trim($sdesc);
$limit = 230;
if (strlen($sdesc) > $limit) {
$sdesc = substr($sdesc, 0, strrpos(substr($sdesc, 0, $limit), ' '));
}
?>
<?php echo $sdesc."..."; ?>
<div><a href="<?php echo $category->getUrl(); ?>" class="go">View <?php echo $category->getName(); ?> <?php echo $catType ?>...</a></div>
</div>
<?php endforeach; ?>
這似乎沒有任何工作。我離開了我的編碼。我也刪除了應該在上面進行過濾的代碼。 – Corey 2015-02-09 19:21:59
http://www.steinjewelrycompany.com/fine-gifts-and-accessories 我只有2個類別目前在下拉列表中的首飾上激活。您將在右側看到Spotlight設計器。勞力士根本不應該出現,它仍然找到方向。勞力士也是貓ID:38。我檢查確定我有很多次正確的ID。 – Corey 2015-02-09 19:23:09
聽起來像是您的$ catIdEx值不正確。在foreach循環中添加<?php echo'ID是:'。$ category-> getId(); ?>確定你試圖排除的那個人擁有你認爲它的ID – PixieMedia 2015-02-09 19:23:55