繁体   English   中英

遍历Magento类别,元关键字和描述

[英]Loop Through Magento Categories, Meta Keywords and Descriptions

我有一个文件可以成功遍历我的类别和子类别。 我能够成功地呼应所有类别及其链接

我不明白为什么这些(关键字和说明)没有回显

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

该文件位于此处app / design / frontend / mystoretheme / default / template / catalog / category / listofcats.phtml

然后将其放置在cms页{{block type =“ catalog / navigation” name =“ catalog.category” template =“ catalog / category / listofcats.phtml”}}的块上

目的是能够在相同的<li>中显示关键字及其描述的每个类别列表,并循环给出这样的列表

  • 类别
  • 关键词
  • 描述

这是我的代码。 由于它们不起作用,因此我省略了对关键字和描述的尝试。

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

请检查以下内容:

<?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/>";
}
?>

暂无
暂无

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

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