質問

カテゴリページにサブカテゴリのリストを表示する次のコードは、いくつかのサブカテゴリを表示から除外したいがナビゲーションメニューでアクティブになっています。
カテゴリツリーシナリオ:

アパレル
---男性
---女性
---子供


---男性
---女性
---子供

上のメニュー/ナビゲーションの一部であるアパレルカテゴリをクリックしたとき。それはアパレルのカテゴリーページに行き、男性、女性、そして子供のサブカテゴリ名とサブカテゴリイメージのみを表示します。しかし、私は子供を除外するために。しかし、あなたが衣料品を服用するとき、それはまだナビゲーションに見えるでしょう3つのサブカテゴリはすべてドロップダウンの一部です。

<ul class="products-grid widget-grid">
     <!--  -->
     <?php
      $currentCat = Mage::registry('current_category');
      if ( $currentCat->getParentId() == Mage::app()->getStore()->getRootCategoryId() ){
         // current category is a toplevel category
         $loadCategory = $currentCat;
         }else{
         // current category is a sub-(or subsub-, etc...)category of a toplevel category
         // load the parent category of the current category
         $loadCategory = Mage::getModel('catalog/category')->load($currentCat->getParentId());
          }
          $subCategories = explode(',', $loadCategory->getChildren());

          foreach ( $subCategories as $subCategoryId )
          {
             $cat = Mage::getModel('catalog/category')->load($subCategoryId);
             if($cat->getIsActive()){
                echo '<li class="grid_3 item alpha">
                <div class="product-border">
                <div class="product-img-box">
                <a href="'.$cat->getURL().'" class="product-image" >
                <div class="hover-box">
                   <img src="'.$cat->getImageUrl().'" />
                   <span class="image-box"></span>
                </div>
                </a>
                <a class="fancybox" rel="category-gallery" title="'.$cat->getName().'" href="'.$cat->getURL().'">&nbsp;</a>
                <h2 class="product-name">
                <a href="'.$cat->getURL().'">'.$cat->getName().'</a>
                <div class="title-divider"><span>&nbsp;</span></div>
                </h2>
                </div>
                </div>
                <div class="clear"></div>
                </li>';
           }
      }
   ?>
     <!--  -->
</ul>
.

あなたの助けを楽しみにしています。ありがとうございました!

役に立ちましたか?

解決

私は最善の方法があると思いますが、カテゴリ一覧ページで管理するために使用できる1つのカテゴリ属性をクレーザにクレーザにすることができます。

たとえば、「はい、いいえ」のオプションを使用して「表示表示」というカテゴリ属性を作成し、このオプションに基づいてリストからこれらのカテゴリをスキップすることができ、それはまだ上位のナビゲーションで利用可能になります。

編集

createAttribute.phpというrootに1つのファイルを作成し、そのファイル内のコードを追加し、ブラウザでURLを実行し、 http://example.com/createattribute.php

これは新しいカテゴリ属性を作成し、管理者で見ることができます。モジュール設定も使用できるのと同じこと。

<?php
require_once("app/Mage.php");
Mage::app('default');
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

$installer = new Mage_Eav_Model_Entity_Setup('core_setup');
$entityTypeId     = $installer->getEntityTypeId('catalog_category');
$attributeSetId   = $installer->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $installer->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);

$installer->addAttribute('catalog_category', 'show_in_list',  array(
    'group'    => 'General Information',
    'type'     => 'int',
    'label'    => 'Show in list',
    'input'    => 'select',
    'global'   => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
    'visible'           => true,
    'required'          => false,
    'user_defined'      => false,
    'default'           => 0,
    'source' => 'eav/entity_attribute_source_boolean'
));
?>
.

あなたが上記に表示されるようにあなたのPHTMLコードにはないだけで、

のようなもう1つの状態を追加するだけです。
if($cat->getIsActive() && $cat->getShowInList()){...
.

これは、adminでオプションはい設定したカテゴリのみをリストします。

ライセンス: CC-BY-SA帰属
所属していません magento.stackexchange
scroll top