创建自定义菜单时检索Magento上类别的网址 [英] Retrieve Url of category on Magento when creating a custom menu

查看:66
本文介绍了创建自定义菜单时检索Magento上类别的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个仅包含几个特定类别及其各自子类别的自定义下拉菜单.到目前为止,我设法检索了子类别的名称,但是链接不起作用.

I am trying to create a custom drop-down-menu with only few specific categories and their respective subcategories. So far I managed to retrieve the Names of the subcategories but links won't work.

如果在Magento的后端进行了更改,我还需要使主类别自动检索其自己的名称和URL.在这种情况下,类别ID为265.

I also need to make the main category retrieve its own name and URL automaticly in case it is changed on the back-end of Magento. In this case the category id is 265.

我正在使用的网站是www.personalproducts4u.co.uk

The website I am working on is www.personalproducts4u.co.uk

<li class="eight"><a href="<?php echo $this->getUrl() ?>index.php/contacts">Hotel Products</a>
 <?php $children = Mage::getModel('catalog/category')->getCategories(265); ?>
 <ul>
 <?php foreach ($children as $category): ?>
 <li>
 <a href="<?php echo $category->getUrl ?>">
 <?php echo $category->getName(); ?>
 </a>
 </li>
 <?php endforeach; ?>
 </ul>
 </li>

推荐答案

问题是$children集合的类型为Varien_Data_Tree_Node_Collection,其元素分别为Varien_Data_Tree_Node类型.在它们上调用getUrl()将返回null,它们不是Mage_Catalog_Model_Category对象.但是,您可以通过调用以下内容来检索其请求路径(url):

The problem is that the $children collection is of type Varien_Data_Tree_Node_Collection and its elements respectively are of type Varien_Data_Tree_Node. Calling getUrl() on them will return null, they are not Mage_Catalog_Model_Category objects. However, you can retrieve their request path (url) by calling:

$category->getRequestPath();

或者,您可以通过调用以下内容来加载类别对象:

Alternatively you can load the category object by calling:

$cat = Mage::getModel('catalog/category')->load($category->getEntityId());

,然后使用$cat->getUrl()调用.不过,这种加载会增加额外的开销.

And then use the $cat->getUrl() call. This loading will add an extra overhead though.

这篇关于创建自定义菜单时检索Magento上类别的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆