dphg63476 2017-06-06 17:38
浏览 43
已采纳

循环通过Magento类别,元关键字和描述

I have a file that is successfully looping through my categories and subcategories. I am successfully able to echo all the categories and their links

BUT

I do not understand why these (keywords and description) are not echoing

<?php echo htmlspecialchars($this->getKeywords()) ?>
<?php echo htmlspecialchars($this->getDescription()) ?>

The file is located here app/design/frontend/mystoretheme/default/template/catalog/category/listofcats.phtml

Then im placing it on a block in a cms page {{block type="catalog/navigation" name="catalog.category" template="catalog/category/listofcats.phtml"}}

The goal is to be able to display each of the categories list of keywords and their descriptions within the same < li > and loop giving me a list like this

  • Category
  • Keywords
  • Description

Here is my code. I have omitted my attempts at keyword and description since they are not working.

<div class="block block-list block-categories">
<div id="block-categories" class="block-title active">
    <strong><span>Categories </span></strong>
</div>  
<div id="leftnav" class="block-content" style="display:block">
    <?php $helper = $this->helper('catalog/category') ?>
        <?php $categories = $this->getStoreCategories() ?>
    <?php if (count($categories) > 0): ?>
        <ul id="leftnav-tree" class="level0">
            <?php foreach($categories as $category): ?>
                <li class="level0<?php if ($this->isCategoryActive($category)): ?> active<?php endif; ?>">
                    <a href="<?php echo $helper->getCategoryUrl($category) ?>"><span><?php echo $this->escapeHtml($category->getName()) ?></span></a>
                    <?php //if ($this->isCategoryActive($category)): ?>
                        <?php $subcategories = $category->getChildren() ?>
                        <?php if (count($subcategories) > 0): ?>
                            <ul id="leftnav-tree-<?php echo $category->getId() ?>" class="level1">
                                <?php foreach($subcategories as $subcategory): ?>
                                    <li class="level1<?php if ($this->isCategoryActive($subcategory)): ?> active<?php endif; ?>">
                                        <a href="<?php echo $helper->getCategoryUrl($subcategory) ?>"><?php echo $this->escapeHtml(trim($subcategory->getName(), '- ')) ?></a>
                                         <?php $secondLevelSubcategories = $subcategory->getChildren() ?>
                                         <?php if (count($secondLevelSubcategories ) > 0): ?>
                            <ul id="leftnav-tree-<?php echo $subcategory->getId() ?>" class="level2">
                                <?php foreach($secondLevelSubcategories as $secondLevelSubcategory ): ?>
                                    <li class="level2<?php if ($this->isCategoryActive($secondLevelSubcategory )): ?> active<?php endif; ?>">
                                        <a href="<?php echo $helper->getCategoryUrl($secondLevelSubcategory ) ?>"><?php echo $this->escapeHtml(trim($secondLevelSubcategory ->getName(), '- ')) ?></a>
                                    </li>
                                    <?php endforeach; ?>
                            </ul>
                            <script type="text/javascript">decorateList('leftnav-tree-<?php echo $category->getId() ?>', 'recursive')</script>
                        <?php endif; ?>
                                <?php endforeach; ?>
                            </ul>
                            <script type="text/javascript">decorateList('leftnav-tree-<?php echo $category->getId() ?>', 'recursive')</script>
                        <?php endif; ?>
                    <?php //endif; ?>
                </li>
            <?php endforeach; ?>
        </ul>
        <script type="text/javascript">decorateList('leftnav-tree', 'recursive')</script>
    <?php endif; ?>
</div>

  • 写回答

1条回答 默认 最新

  • dongma1666 2017-06-07 07:45
    关注

    Please check this:

    <?php
    $categories = Mage::getModel('catalog/category')
                    ->getCollection()
                    ->setStoreId(Put the store id here)
                    ->addAttributeToSelect('*')
                    ->addIsActiveFilter();
    foreach ($categories as $category) {
        echo $category->getName();
        echo "-";
        echo $category->getMetaKeywords();
        echo "-";
        echo $category->getMetaDescription();
        echo "<br/>";
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等