Magento“输了”进入子类别时的类别

发布于 2024-10-03 18:29:40 字数 989 浏览 7 评论 0原文

好吧,我已经使用 Magento 大约 1-2 个月了,对此并不太兴奋,但仍在努力学习。

我已经设法为某人安装了一个不错的模板主题,目前我正在调整以使其“正确”工作。

但是,我有一个奇怪的问题......首先,我的模板没有在顶部导航中显示根类别,只列出了第一个子类别。这很好。

我进入一个子类别,我可以在左侧块中看到子类别。但是,当我单击其中一个子子类别时,左侧块根本不显示任何类别。

我可以看出这是默认行为,因为我所在的子子类别没有子子子类别。但是,我想知道,当您处于孙子类别时,有谁知道有什么好方法来显示主基地中的所有类别?

EX:
Default Category (Not seen)
  Cat 1 (Shown in top nav)
    Sub Cat 1
    Sub Cat 2
  Cat 2 (Shown in top nav)
    Sub Cat 1
    Sub Cat 2
  Cat 3 (Shown in top nav)
    Sub Cat 1
    Sub Cat 2

举例来说,我在 Cat 3 位置单击 Sub Cat 2,我可以让 magento 显示第 2 层的所有子项吗?在此示例中,将显示 Cat 3 及其所有子类别,几乎就像我只单击了 Cat 3 一样。

我希望我能很好地解释这一点,我和下一个人一样对 Magento 感到困惑。 ..

(这是在 foreach 循环之前在我的模板文件中写入类别的部分。无论如何,在这里抛出一个 getParent() 类型的交易,以便它总是加载“顶部”类别?)

<?php $_categories=$this->getCurrentChildCategories(); ?>

<?php $_count = is_array($_categories)?count($_categories):$_categories->count(); ?>

<?php if($_count): ?>

Alright, so I've been working with Magento for about 1-2 months, not too excited about it, but still trying to learn.

I've managed to install a nice Template theme for someone, and I'm currently tweaking to make it work "right".

But, I have a bit of a weird issue... firstly, my Template doesn't show root categories in the top nav, just lists the first sub categories. This is fine.

I go into a sub category, and I can see the subcategories in the left block. But when I click on one of the sub-sub-categories, the left block doesn't display any categories at all.

I can figure out that this is default behavior, because the sub-sub category I'm in has no sub-sub-sub categories. But, I was wondering, does anyone know of a good way to, when you're in a grandchilded category, to show all the categories in the main base?

EX:
Default Category (Not seen)
  Cat 1 (Shown in top nav)
    Sub Cat 1
    Sub Cat 2
  Cat 2 (Shown in top nav)
    Sub Cat 1
    Sub Cat 2
  Cat 3 (Shown in top nav)
    Sub Cat 1
    Sub Cat 2

Say for example I click on Sub Cat 2, in the Cat 3 location, could I have magento display ALL the children from the 2nd level? In this example, Cat 3 would be shown, with all it's sub-categories as well, almost as if I had clicked on just Cat 3.

I hope I explained this well, I'm about as confused with Magento as the next person...

(Here's the bit before the foreach loop to write the categories in my template file. Anyway to throw a getParent() kind of a deal in here so it always loads the 'top' category?)

<?php $_categories=$this->getCurrentChildCategories(); ?>

<?php $_count = is_array($_categories)?count($_categories):$_categories->count(); ?>

<?php if($_count): ?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

魔法少女 2024-10-10 18:29:40

好的。我查看了提供的两个答案,但是,它们实际上都没有朝着我正在寻找的方向发展。

它们本身都很好,但是,我偶然发现了一些东西,给了我更好的线索,我编写了这个敏捷的程序:

// Get the current category's path, in array.
// Ex: [0] => '20', [1] => '4'
$_categorypath = $this->getCurrentCategoryPath();

// Use Mage to get a requested Category from the category path from above.
// (The last int in the array is the top-most category, so size-1 gets last int id)
$_parent_category = Mage::getModel('catalog/category')->load($_categorypath[count($_categorypath)-1]);

// Call the children categories from the loaded category
$_categories=$_parent_category->getChildrenCategories();

// Follow the rest of the loop... Success! No "Current/Active" handler yet.. 
$_count = is_array($_categories)?count($_categories):$_categories->count();

if($_count):
// ( Run your foreach code here, complete with html formatting)

我希望这对将来正在寻找类似功能的其他人有所帮助。

Ok. I had a look at both of the answers provided, however, neither of them actually went the direction I was looking.

They were good in both their own accord, however, I stumbled upon something that gave me a better clue, and I programmed this snippy:

// Get the current category's path, in array.
// Ex: [0] => '20', [1] => '4'
$_categorypath = $this->getCurrentCategoryPath();

// Use Mage to get a requested Category from the category path from above.
// (The last int in the array is the top-most category, so size-1 gets last int id)
$_parent_category = Mage::getModel('catalog/category')->load($_categorypath[count($_categorypath)-1]);

// Call the children categories from the loaded category
$_categories=$_parent_category->getChildrenCategories();

// Follow the rest of the loop... Success! No "Current/Active" handler yet.. 
$_count = is_array($_categories)?count($_categories):$_categories->count();

if($_count):
// ( Run your foreach code here, complete with html formatting)

I hope this helps someone else in the future, who is looking for a similar feature.

天生の放荡 2024-10-10 18:29:40

有一个垂直导航扩展,它为您提供了更多选择超过所显示的内容。它没有您所描述的确切行为,但这是朝着正确方向迈出的一步,您可能会发现修改比完全提出自己的方法更容易。

There is a vertical navigation extension which gives you more choice over what is shown. It doesn't have the exact behaviour you describe but is a step in the right direction and you may find it easier to modify than coming up with your own method entirely.

黎夕旧梦 2024-10-10 18:29:40

左侧类别块的想法是显示当前类别的子类别。听起来您想要一个更静态的菜单,始终显示相同的类别树。这正是顶部导航的作用,因此您只需从那里复制代码,并将其用作左侧块。它甚至具有 .active CSS 类,因此您可以根据活动类别对其进行样式设置以折叠/展开子类别。

The idea of the left category block is to show child categories of the current category. It sounds like you want a more static menu that always shows the same category tree. That is exactly what the top navigation does, so you can just copy the code from there, and use it as a left block. It even has .active CSS classes, so you can style it to collapse/expand subcategories based on the active category.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文