Magento 类别排序
Magento Category sorting
我的 magento 解决方案有一段自定义代码,它在静态块元素中显示图像和文本,使我能够直观地表示类别视图。
然而,即使代码应该根据它们在管理面板中的位置对我的类别进行排序,但这并没有发生。
我坐在 magento 1 上。9.x.x 解决方案,这是我的代码,希望有人能在这里有所了解。
<?php
$category = Mage::getSingleton('catalog/layer')->getCurrentCategory();
$categories = $category->getCollection()
->addAttributeToSelect(array('name', 'image'))
->addAttributeToFilter('is_active', 1)
->addAttributeToFilter('include_in_menu', 1)//if not to show in nav
->addIdFilter($category->getChildren())
->addAttributeToSort(‘position’,'ASC');
?>
<?php $_columnCount = 4; ?>
<?php if ($i++%$_columnCount==0): ?>
<ul class="catblocks">
<?php foreach ($categories as $category): ?>
<li class="item<?php if(($i-1)%$_columnCount==0): ?> first <?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
<a href="<?php echo $category->getUrl() ?>">
<img src="<?php echo Mage::getBaseUrl('media') . 'catalog' . DS . 'category' . DS . $category->getImage() ?>"
alt="<?php echo $this->htmlEscape($category->getName()) ?>" />
<span><?php echo $category->getName() ?></span>
</a>
<?php $i++ ?>
</li>
<?php endforeach; ?>
<?php endif; ?>
</ul>
在您的代码中,addAttributeToSort(‘position’,'ASC')
在 'position' 周围使用了非 ASCII 引号,结尾的 </ul>
应该在 endif;
之前,因为开始标记出现在if 语句。
<?php
$category = Mage::getSingleton('catalog/layer')->getCurrentCategory();
$categories = $category->getCollection()
->addAttributeToSelect(array('name', 'image'))
->addAttributeToFilter('is_active', 1)
->addAttributeToFilter('include_in_menu', 1)//if not to show in nav
->addIdFilter($category->getChildren())
->addAttributeToSort('position','ASC');
?>
<?php $_columnCount = 4; ?>
<?php if ($i++%$_columnCount==0): ?>
<ul class="catblocks">
<?php foreach ($categories as $category): ?>
<li class="item<?php if(($i-1)%$_columnCount==0): ?> first <?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
<a href="<?php echo $category->getUrl() ?>">
<img src="<?php echo Mage::getBaseUrl('media') . 'catalog' . DS . 'category' . DS . $category->getImage() ?>"
alt="<?php echo $this->htmlEscape($category->getName()) ?>" />
<span><?php echo $category->getName() ?></span>
</a>
<?php $i++ ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
我的 magento 解决方案有一段自定义代码,它在静态块元素中显示图像和文本,使我能够直观地表示类别视图。
然而,即使代码应该根据它们在管理面板中的位置对我的类别进行排序,但这并没有发生。
我坐在 magento 1 上。9.x.x 解决方案,这是我的代码,希望有人能在这里有所了解。
<?php
$category = Mage::getSingleton('catalog/layer')->getCurrentCategory();
$categories = $category->getCollection()
->addAttributeToSelect(array('name', 'image'))
->addAttributeToFilter('is_active', 1)
->addAttributeToFilter('include_in_menu', 1)//if not to show in nav
->addIdFilter($category->getChildren())
->addAttributeToSort(‘position’,'ASC');
?>
<?php $_columnCount = 4; ?>
<?php if ($i++%$_columnCount==0): ?>
<ul class="catblocks">
<?php foreach ($categories as $category): ?>
<li class="item<?php if(($i-1)%$_columnCount==0): ?> first <?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
<a href="<?php echo $category->getUrl() ?>">
<img src="<?php echo Mage::getBaseUrl('media') . 'catalog' . DS . 'category' . DS . $category->getImage() ?>"
alt="<?php echo $this->htmlEscape($category->getName()) ?>" />
<span><?php echo $category->getName() ?></span>
</a>
<?php $i++ ?>
</li>
<?php endforeach; ?>
<?php endif; ?>
</ul>
在您的代码中,addAttributeToSort(‘position’,'ASC')
在 'position' 周围使用了非 ASCII 引号,结尾的 </ul>
应该在 endif;
之前,因为开始标记出现在if 语句。
<?php
$category = Mage::getSingleton('catalog/layer')->getCurrentCategory();
$categories = $category->getCollection()
->addAttributeToSelect(array('name', 'image'))
->addAttributeToFilter('is_active', 1)
->addAttributeToFilter('include_in_menu', 1)//if not to show in nav
->addIdFilter($category->getChildren())
->addAttributeToSort('position','ASC');
?>
<?php $_columnCount = 4; ?>
<?php if ($i++%$_columnCount==0): ?>
<ul class="catblocks">
<?php foreach ($categories as $category): ?>
<li class="item<?php if(($i-1)%$_columnCount==0): ?> first <?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
<a href="<?php echo $category->getUrl() ?>">
<img src="<?php echo Mage::getBaseUrl('media') . 'catalog' . DS . 'category' . DS . $category->getImage() ?>"
alt="<?php echo $this->htmlEscape($category->getName()) ?>" />
<span><?php echo $category->getName() ?></span>
</a>
<?php $i++ ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>