0 レビュー
3 回答
php-Magentoの製品カテゴリを列ごとに表示する方法
メインタイトルの下にすべてのカテゴリを表示しようとしているので、各列に4つのカテゴリを表示したいと思います。以下は私のコードです
<?php
$_category = $this->getCurrentCategory();
$collection = Mage::getModel('catalog/category')->getCategories($_category->entity_id);
$helper = Mage::helper('catalog/category');
?>
<ul class="pull-left">
<?php foreach ($collection as $cat):?>
<li>
<a style="color:#fff;" href="<?php echo $helper->getCategoryUrl($cat);?>">
<cite><?php echo $cat->getName();?><?php
?></cite>
</a>
</li>
<?php endforeach;?>
</ul>
HTML出力
<ul class="pull-left">
<li>....</li>
<li>....</li>
<li>....</li>
<li>....</li>
<li>....</li>
<li>....</li>
<li>....</li>
<li>....</li>
.
.
.
.
</ul>
すべてのul
に4つのli
アイテムを定義したいと思います。このように
- ...
- ...
- ...
- ...
- ...
- ...
- ...
- ...
製品数も表示したいので、これを試しました
<?php
$products_count = Mage::getModel('catalog/category')->load($categoryId)->getProductCount();
?>
しかし、機能していません。
わからない
0
レビュー
答え :
解決策:
カテゴリページでこのコードを使用していますが、カウントされています。 タグの前に追加したコードをご覧ください。
<?php
$loadCategory = Mage::registry('current_category');
//echo 'loadCategory = '.$_categoryID = $loadCategory->getId();
$subCategories = explode(',', $loadCategory->getChildren());
?>
<ul class="pull-left">
<?php $i=1;
foreach ( $subCategories as $subCategoryId )
{
$cat = Mage::getModel('catalog/category')->load($subCategoryId);
if($cat->getIsActive())
{
if($cat->getImageUrl())
{
//echo '<a href="'.$cat->getURL().'">'.$cat->getName().'</a></br>';
echo '<li>';
echo '<a style="color:#fff;" href="'.$cat->getUrl().'">'.$this->escapeHtml($cat->getName()); echo"<br>";
echo $total = Mage::getModel('catalog/layer')->setCurrentCategory($subCategoryId)->getProductCollection()->getSize();
echo'</a>';
echo '</li>';
if($i%4==0)
{
echo'</ul><ul class="pull-left">';
}
}
}
$i++;
}
?>
わからない
0
レビュー
答え :
解決策:
このコードを使用してください。これはきっとあなたのために働くでしょう。
<?php
$category = Mage::getModel('catalog/category')->load($categoryID);
echo $total = Mage::getModel('catalog/layer')->setCurrentCategory($category)->getProductCollection()->getSize();
?>
ありがとう
わからない
0
レビュー
答え :
解決策:
これを使用してください。
必要に応じてul、liを調整できます。現在、これにより4つのサブカテゴリが1行に一覧表示されます。
このコードは、親カテゴリのサブカテゴリを提供します。
<?php
$loadCategory = Mage::registry('current_category');
//echo 'loadCategory = '.$_categoryID = $loadCategory->getId();
$subCategories = explode(',', $loadCategory->getChildren());
?>
<ul class="pull-left">
<?php $i=1;
foreach ( $subCategories as $subCategoryId )
{
$cat = Mage::getModel('catalog/category')->load($subCategoryId);
if($cat->getIsActive())
{
if($cat->getImageUrl())
{
//echo '<a href="'.$cat->getURL().'">'.$cat->getName().'</a></br>';
echo '<li>';
echo '<a style="color:#fff;" href="'.$cat->getUrl().'">'.$this->escapeHtml($cat->getName()).'</a>';
echo '</li>';
if($i%4==0)
{
echo'</ul><ul class="pull-left">';
}
}
}
$i++;
}
?>
</ul>
わからない
同様の質問
私たちのウェブサイトで同様の質問で答えを見つけてください。