Php 链接到类别magento
我正在寻找一个在magento主页滑块上的产品链接到它所属的类别。。。到目前为止,我已经:Php 链接到类别magento,php,magento,categories,Php,Magento,Categories,我正在寻找一个在magento主页滑块上的产品链接到它所属的类别。。。到目前为止,我已经: <?php $allIds = $product->getCategoryIds(); foreach($allIds as $categoryId) { $category = Mage::getModel('catalog/category')->load($categoryId); ?> <a href="<?ph
<?php
$allIds = $product->getCategoryIds();
foreach($allIds as $categoryId) {
$category = Mage::getModel('catalog/category')->load($categoryId);
?>
<a href="<?php echo $category->getCategoryUrl() ?>"><?php echo$category->getName() ?></a><br/>
<?php
}
?>
(这在foreach项目中运行)这为我提供了类别(这很好),但是:
似乎没有链接到正确的位置(它实际上没有给我任何东西)。有人能帮上忙吗?试试这个
<?php echo Mage::helper('catalog/category')->getCategoryUrl($category);?>
试试这个
<?php echo Mage::helper('catalog/category')->getCategoryUrl($category);?>
如果只想显示一个类别链接,则无需在循环中加载类别:
$category = $product->getCategory();
$url = $category->getUrl();
$category = $product->getCategoryCollection()->getFirstItem();
更新:我刚刚意识到第一行在主页上可能不起作用。但您仍然不需要循环:
$category = $product->getCategory();
$url = $category->getUrl();
$category = $product->getCategoryCollection()->getFirstItem();
如果只想显示一个类别链接,则不需要在循环中加载类别:
$category = $product->getCategory();
$url = $category->getUrl();
$category = $product->getCategoryCollection()->getFirstItem();
更新:我刚刚意识到第一行在主页上可能不起作用。但您仍然不需要循环:
$category = $product->getCategory();
$url = $category->getUrl();
$category = $product->getCategoryCollection()->getFirstItem();
您将在此处找到与显示类别和子类别相关的所有内容。希望这会对您有所帮助。您将在此处找到与显示类别和子类别相关的所有内容。希望这将是有帮助的。这似乎会破坏它,调用后不会加载任何内容。这似乎会破坏它,调用后不会加载任何内容。如果我只是回显此$url=$category->getUrl();如果我只回显这个$url=$category->getUrl();书页从此处开始分出。