循环遍历Magento类别,Meta关键字和描述
我有一个文件,正在循环通过我的类别和子类别。我能够成功地呼应所有我不明白的类别及其链接循环遍历Magento类别,Meta关键字和描述
但
为什么这些(keywords和description)不附和
<?php echo htmlspecialchars($this->getKeywords()) ?>
<?php echo htmlspecialchars($this->getDescription()) ?>
该文件位于这里 应用程序/设计/前端/ mystoretheme /默认/模板/目录/类别/ listofcats.phtml
然后即时将它放在一个cms页面块{{块类型=“目录/导航”名称=“catalog.category”模板=“目录/类别/ listofca ts.phtml“}}
我们的目标是能够在同一<李中显示的每个关键字及其说明的类别列表>和循环给我这样
- 类别 列表
- 关键词
- 说明
这里是我的代码。由于他们不工作,我省略了关键字和描述的尝试。
<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/>";
}
?>
但是,这很好,我只需要显示我在不是所有商店类别上显示网页的商店。我将如何修改它? – monjexpress
只需执行以下操作: - > setStoreId($ storeId)请输入您想要的商店的商店标识。 –
请参阅我上面修改的答案。如果你喜欢它并且工作正常,那么请接受答案+向上投票。谢谢。 –
什么版本的Magento您使用的是? – spiil