EC-CUBE カテゴリーリストを開閉式にした時に親カテゴリーへのリンクを設置
2015/11/18
⚠️投稿日または最終更新日から8年以上経過している内容です。
確認バージョン 2.13.4

カテゴリーリストを開閉式にした時に、 親カテゴリーへのリンクが開閉式のトリガーになることも多いと思います。 別途開閉用のボタンを設置するのもありですが…。
そこで今回は smarty を駆使して「カテゴリーのすべて」というリンクを生成して、 開いたときにそれを表示できるようにしてみました。
/data/Smarty/templates/default/frontparts/bloc/category_tree_fork.tpl
<ul <!--{if $treeID != ""}-->id="<!--{$treeID}-->"<!--{/if}--> style="<!--{if !$display}-->display: none;<!--{/if}-->">
<!-- ↓↓↓こんな感じのを追加 -->
<!--{if isset($child.children|smarty:nodefaults)}-->
<li class="level<!--{math equation="1 + level" level=$child.level}--><!--{if in_array($child.category_id, $tpl_category_id)}--> onmark<!--{/if}-->">
<a href="<!--{$smarty.const.ROOT_URLPATH}-->products/list.php?category_id=<!--{$child.category_id}-->"<!--{if in_array($child.category_id, $tpl_category_id)}--> class="onlink"<!--{/if}-->><!--{$child.category_name|h}-->のすべて(<!--{$child.product_count|default:0}-->)</a>
</li>
<!--{/if}-->
<!-- ↑↑↑こんな感じのを追加 -->
<!--{foreach from=$children item=child}-->
<li class="level<!--{$child.level}--><!--{if in_array($child.category_id, $tpl_category_id)}--> onmark<!--{/if}-->">
<a href="<!--{$smarty.const.ROOT_URLPATH}-->products/list.php?category_id=<!--{$child.category_id}-->"<!--{if in_array($child.category_id, $tpl_category_id)}--> class="onlink"<!--{/if}-->><!--{$child.category_name|h}-->(<!--{$child.product_count|default:0}-->)</a>
<!--{if in_array($child.category_id, $arrParentID)}-->
<!--{assign var=disp_child value=1}-->
<!--{else}-->
<!--{assign var=disp_child value=0}-->
<!--{/if}-->
<!--{if isset($child.children|smarty:nodefaults)}-->
<!--{include file="`$smarty.const.TEMPLATE_REALDIR`frontparts/bloc/category_tree_fork.tpl" children=$child.children display=$disp_child}-->
<!--{/if}-->
</li>
<!--{/foreach}-->
</ul>