简体   繁体   中英

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.

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)

                <?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:

<?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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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