简体   繁体   English

Magento在.phtml文件中的导航中获取类别和列表

[英]Magento get categories and list in navigation in .phtml file

Ok so I've copied and pasted like 10 inserts already for php code to list the main categories or the sub categories under the Default root category. 好的,所以我已经为PHP代码复制并粘贴了10个插入内容,以列出Default根目录类别下的主要类别或子类别。

None of them are displaying my categories and I have all my categories as root categories AND sub-categories under the Default root category to see if both scenarios will work.. 他们都没有显示我的类别,我将所有类别都作为“默认”根类别下的根类别和子类别,以查看这两种情况是否都可以。

Here is my php code I have in my theme .phtml file (1-column so far) 这是我在主题.phtml文件中的php代码(到目前为止1列)

                <?php $_categories = Mage::helper('catalog/category')->getStoreCategories(); ?>
                <?php if (count($_categories) > 0): ?>
                <ul>
                    <?php foreach($_categories as $_category): ?>
                        <li>
                            <a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
                                <?php echo $_category->getName() ?>
                            </a>
                        </li>
                    <?php endforeach; ?>
                </ul>
                <?php endif; ?>

I know I have them setup right in the admin panel because I have them both as root and subcategories which shouldn't be necessary of course. 我知道我已经在管理面板中设置了它们,因为我将它们同时设置为根目录和子目录,这当然不是必需的。 I'm just trying everything to get them to display and nothing seems to be working.. 我只是想尽一切办法让它们显示,但似乎没有任何效果。

Anyone know? 有人知道吗

EDIT Ok I found it in topmenu.phtml in the html directory under the template directory in the page directory: 编辑好,我在页面目录中模板目录下的html目录的topmenu.phtml中找到它:

<?php $_menu = $this->getHtml('level-top') ?>
<?php if($_menu): ?>
<div class="nav-container">
    <ul id="nav">
        <?php echo $_menu ?>
    </ul>
</div>
<?php endif ?>

Where is the getHtml('level-top') code at so I can alter the markup of the li elements? getHtml('level-top')代码在哪里,以便我可以更改li元素的标记?

对于更改标记,您需要在Mage_Page_Block_Html_Topmenu类中重写受保护的_getHtml方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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