0

私は Opencart 1.5.1.1 を使用しており、各トップ メニュー カテゴリの説明メタ タグを取得し、それぞれのドロップダウン メニューのヘッダー (リンクではなくテキストのみ) として表示する必要があります。多かれ少なかれ、次のようになります。

Item1、Item2 - 通常のトップ メニュー項目
Super Item1 - 説明メタ タグ付きのドロップダウン ヘッダー
subitem1、subitem2、... - サブカテゴリ ドロップダウン

画像は載せませんので、ご理解いただけると幸いです。

画像に関しては、StackOverflow で許可されていません。もっとポイントが必要です。

catalog\view\theme\default\template\common\header.tpl のメニュー コードは次のとおりです。

<?php if ($categories) { ?>
<div id="menu">
  <ul>
    <?php foreach ($categories as $category) { ?>
    <li><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
      <?php if ($category['children']) { ?>
      <div>
        <?php for ($i = 0; $i < count($category['children']);) { ?>
        <ul><p><?php echo $category['meta_description']; ?></p><!-----HERE------->
          <?php $j = $i + ceil(count($category['children']) / $category['column']); ?>
          <?php for (; $i < $j; $i++) { ?>
          <?php if (isset($category['children'][$i])) { ?>
          <li><a href="<?php echo $category['children'][$i]['href']; ?>"><?php echo $category['children'][$i]['name']; ?></a></li>
          <?php } ?>
          <?php } ?>
        </ul>
        <?php } ?>
      </div>
      <?php } ?>
    </li>
    <?php } ?>
  </ul>
</div>

上記のコードで遊んでみましたが、未定義のインデックス通知が表示されました ($category['meta_description'] を試したとき)\

または、現在のページに応じてすべてのドロップダウンに同じメタ説明 ($description を使用する場合)\ たとえば、ホームページの場合はストアの説明、カテゴリ 1 ページの場合はカテゴリ 1 の説明など。

さらに別のファイルが原因である可能性がありますが、そこを変更する方法がわかりません。ファイル catalog\controller\common\header.php とコードは次のとおりです。

// Menu
        $this->load->model('catalog/category');
        $this->load->model('catalog/product');

        $this->data['categories'] = array();

        $categories = $this->model_catalog_category->getCategories(0);

        foreach ($categories as $category) {
            if ($category['top']) {
                $children_data = array();

                $children = $this->model_catalog_category->getCategories($category['category_id']);

                foreach ($children as $child) {
                    $data = array(
                        'filter_category_id'  => $child['category_id'],
                        'filter_sub_category' => true   
                    );      

                    $product_total = $this->model_catalog_product->getTotalProducts($data);

                    $children_data[] = array(
                        'name'  => $child['name'] . ' (' . $product_total . ')',
                        'href'  => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])   
                    );                  
                }

                // Level 1
                $this->data['categories'][] = array(
                    'name'     => $category['name'],
                    'children' => $children_data,
                    'column'   => $category['column'] ? $category['column'] : 1,
                    'href'     => $this->url->link('product/category', 'path=' . $category['category_id'])
                );
            }
        }
4

0 に答える 0