Index: branches/version-2_12-dev/data/class/util/SC_Utils.php
===================================================================
--- branches/version-2_12-dev/data/class/util/SC_Utils.php	(revision 22567)
+++ branches/version-2_12-dev/data/class/util/SC_Utils.php	(revision 22586)
@@ -1922,3 +1922,47 @@
         return $return;
     }
+
+    /**
+     * 
+     * @param string $primary_key
+     * @param string $glue_key
+     * @param integer $max_depth
+     * @param array $correction
+     * @param integer $base_id
+     * @return array ツリーの配列
+     */
+    public static function buildTree($primary_key, $glue_key, $max_depth, $correction = array(), $base_id = 0)
+    {
+        $children = array();
+        foreach ($correction as $child) {
+            $children[$child[$glue_key]][] = $child;
+        }
+        $arrTree = $children[$base_id];
+        foreach ($arrTree as &$child) {
+            SC_Utils_Ex::addChild($child, $primary_key, 1, $max_depth, $children);
+        }
+        return $arrTree;
+    }
+
+    /**
+     * ツリーの親子をつなげるルーチン.
+     * 
+     * @param array $target 親
+     * @param string $primary_key 主キーの識別子
+     * @param integer $level 親の階層
+     * @param integer $max_depth 階層の深さの最大値
+     * @param array $children 子の配列（キーが親ID）
+     * @return void
+     */
+    public static function addChild(&$target, $primary_key, $level, $max_depth, &$children = array())
+    {
+        if (isset($children[$target[$primary_key]])) {
+            $target['children'] = $children[$target[$primary_key]];
+            if ($level + 1 < $max_depth) {
+                foreach ($target['children'] as &$child) {
+                    SC_Utils_Ex::addChild($child, $primary_key, $level++, $max_depth, $children);
+                }
+            }
+        }
+    }
 }
Index: branches/version-2_12-dev/data/class/pages/frontparts/bloc/LC_Page_FrontParts_Bloc_Category.php
===================================================================
--- branches/version-2_12-dev/data/class/pages/frontparts/bloc/LC_Page_FrontParts_Bloc_Category.php	(revision 22567)
+++ branches/version-2_12-dev/data/class/pages/frontparts/bloc/LC_Page_FrontParts_Bloc_Category.php	(revision 22586)
@@ -132,4 +132,5 @@
         $objQuery =& SC_Query_Ex::getSingletonInstance();
         $objDb = new SC_Helper_DB_Ex();
+
         $col = '*';
         $from = 'dtb_category left join dtb_category_total_count ON dtb_category.category_id = dtb_category_total_count.category_id';
@@ -142,4 +143,7 @@
         $objQuery->setOption('ORDER BY rank DESC');
         $arrRet = $objQuery->select($col, $from, $where);
+
+        $arrTree = SC_Utils_Ex::buildTree('category_id', 'parent_category_id', 10, $arrRet);
+
         foreach ($arrParentCategoryId as $category_id) {
             $arrParentID = $objDb->sfGetParents(
@@ -162,12 +166,8 @@
             );
             $this->root_parent_id[] = $arrParentID[0];
-            $arrDispID = array_merge($arrBrothersID, $arrChildrenID);
-            foreach ($arrRet as &$arrCategory) {
-                if (in_array($arrCategory['category_id'], $arrDispID)) {
-                    $arrCategory['display'] = 1;
-                }
-            }
-        }
-        return $arrRet;
+            $this->arrDispID = array_merge($arrBrothersID, $arrChildrenID);
+        }
+
+        return $arrTree;
     }
 
Index: branches/version-2_12-dev/data/Smarty/templates/sphone/frontparts/bloc/category.tpl
===================================================================
--- branches/version-2_12-dev/data/Smarty/templates/sphone/frontparts/bloc/category.tpl	(revision 22206)
+++ branches/version-2_12-dev/data/Smarty/templates/sphone/frontparts/bloc/category.tpl	(revision 22586)
@@ -25,50 +25,5 @@
     <h2 class="title_block">商品カテゴリ</h2>
     <nav id="categorytree">
-        <ul id="categorytreelist">
-            <!--{assign var=preLev value=1}-->
-            <!--{assign var=firstdone value=0}-->
-            <!--{section name=cnt loop=$arrTree}-->
-                <!--{* インデントは Smarty 構文を優先としています。 *}-->
-                <!--{* カテゴリ表示・非表示切り替え *}-->
-                <!--{if $arrTree[cnt].view_flg != "2"}-->
-                    <!--{* 表示フラグがTRUEなら表示 *}-->
-                    <!--{assign var=level value=`$arrTree[cnt].level`}-->
-                    <!--{* level2以下なら表示（level指定可能） *}-->
-                    <!--{if $level <= 5 || $arrTree[cnt].display == 1}-->
-                        <!--{assign var=levdiff value=`$level-$preLev`}-->
-                        <!--{if $levdiff > 0}-->
-                            <ul>
-                        <!--{elseif $levdiff == 0 && $firstdone == 1}-->
-                            </li>
-                        <!--{elseif $levdiff < 0}-->
-                            <!--{section name=d loop=`$levdiff*-1`}-->
-                                    </li>
-                                </ul>
-                            <!--{/section}-->
-                            </li>
-                        <!--{/if}-->
-
-                        <li class="level<!--{$level}--><!--{if in_array($arrTree[cnt].category_id, $tpl_category_id)}--> onmark<!--{/if}-->"><span class="category_header"></span><span class="category_body"><a rel="external" href="<!--{$smarty.const.ROOT_URLPATH}-->products/list.php?category_id=<!--{$arrTree[cnt].category_id}-->"<!--{if in_array($arrTree[cnt].category_id, $tpl_category_id)}--> class="onlink"<!--{/if}-->><!--{$arrTree[cnt].category_name|h}-->(<!--{$arrTree[cnt].product_count|default:0}-->)</a></span>
-                        <!--{if $firstdone == 0}-->
-                            <!--{assign var=firstdone value=1}-->
-                        <!--{/if}-->
-                        <!--{assign var=preLev value=`$level`}-->
-                    <!--{/if}-->
-
-                    <!--{* セクションの最後に閉じタグを追加 *}-->
-                    <!--{if $smarty.section.cnt.last}-->
-                        <!--{if $preLev-1 > 0}-->
-                            <!--{section name=d loop=`$preLev-1`}-->
-                                    </li>
-                                </ul>
-                            <!--{/section}-->
-                            </li>
-                        <!--{else}-->
-                            </li>
-                        <!--{/if}-->
-                    <!--{/if}-->
-                <!--{/if}-->
-            <!--{/section}-->
-        </ul>
+        <!--{include file="`$smarty.const.SMARTPHONE_TEMPLATE_REALDIR`frontparts/bloc/category_tree_fork.tpl" children=$arrTree treeID="categorytreelist"}-->
 
         <script>//<![CDATA[
Index: branches/version-2_12-dev/data/Smarty/templates/sphone/frontparts/bloc/category_tree_fork.tpl
===================================================================
--- branches/version-2_12-dev/data/Smarty/templates/sphone/frontparts/bloc/category_tree_fork.tpl	(revision 22586)
+++ branches/version-2_12-dev/data/Smarty/templates/sphone/frontparts/bloc/category_tree_fork.tpl	(revision 22586)
@@ -0,0 +1,32 @@
+<!--{*
+ * This file is part of EC-CUBE
+ *
+ * Copyright(c) 2000-2013 LOCKON CO.,LTD. All Rights Reserved.
+ *
+ * http://www.lockon.co.jp/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *}-->
+
+<ul<!--{if $treeID != ""}--> id="<!--{$treeID}-->"<!--{/if}-->>
+<!--{foreach from=$children item=child}-->
+    <li<!--{if $child.view_flg == "2" || $child.level > 5 || !in_array($child.category_id, $arrDispID)}--> style="display: none;"<!--{/if}--> class="level<!--{$child.level}--><!--{if in_array($child.category_id, $tpl_category_id)}--> onmark<!--{/if}-->">
+        <span class="category_header"></span><span class="category_body"><a rel="external" 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></span>
+        <!--{if isset($child.children|smarty:nodefaults)}-->
+            <!--{include file="`$smarty.const.SMARTPHONE_TEMPLATE_REALDIR`frontparts/bloc/category_tree_fork.tpl" children=$child.children treeID=""}-->
+        <!--{/if}-->
+    </li>
+<!--{/foreach}-->
+</ul>
Index: branches/version-2_12-dev/data/Smarty/templates/default/frontparts/bloc/category.tpl
===================================================================
--- branches/version-2_12-dev/data/Smarty/templates/default/frontparts/bloc/category.tpl	(revision 22206)
+++ branches/version-2_12-dev/data/Smarty/templates/default/frontparts/bloc/category.tpl	(revision 22586)
@@ -26,50 +26,10 @@
     });
 //]]></script>
+
 <div class="block_outer">
     <div id="category_area">
         <div class="block_body">
             <h2><img src="<!--{$TPL_URLPATH}-->img/title/tit_bloc_category.gif" alt="商品カテゴリ" /></h2>
-            <!--{strip}-->
-                <ul id="categorytree">
-                    <!--{assign var=preLev value=1}-->
-                    <!--{assign var=firstdone value=0}-->
-                    <!--{section name=cnt loop=$arrTree}-->
-                        <!--{* 表示フラグがTRUEなら表示 *}-->
-                        <!--{if $arrTree[cnt].display == 1}-->
-                            <!--{assign var=level value=`$arrTree[cnt].level`}-->
-                            <!--{assign var=levdiff value=`$level-$preLev`}-->
-                                <!--{if $levdiff > 0}-->
-                                    <ul>
-                                <!--{elseif $levdiff == 0 && $firstdone == 1}-->
-                                    </li>
-                                <!--{elseif $levdiff < 0}-->
-                                    <!--{section name=d loop=`$levdiff*-1`}-->
-                                            </li>
-                                        </ul>
-                                    <!--{/section}-->
-                                    </li>
-                                <!--{/if}-->
-                            <li class="level<!--{$level}--><!--{if in_array($arrTree[cnt].category_id, $tpl_category_id)}--> onmark<!--{/if}-->">
-                                <p>
-                                    <a href="<!--{$smarty.const.ROOT_URLPATH}-->products/list.php?category_id=<!--{$arrTree[cnt].category_id}-->"<!--{if in_array($arrTree[cnt].category_id, $tpl_category_id)}--> class="onlink"<!--{/if}-->><!--{$arrTree[cnt].category_name|h}-->(<!--{$arrTree[cnt].product_count|default:0}-->)</a>
-                                </p>
-                            <!--{if $firstdone == 0}--><!--{assign var=firstdone value=1}--><!--{/if}-->
-                            <!--{assign var=preLev value=`$level`}-->
-                        <!--{/if}-->
-                        <!--{* セクションの最後に閉じタグを追加 *}-->
-                        <!--{if $smarty.section.cnt.last}-->
-                            <!--{if $preLev-1 > 0}-->
-                                <!--{section name=d loop=`$preLev-1`}-->
-                                    </li>
-                                </ul>
-                                <!--{/section}-->
-                                </li>
-                            <!--{else}-->
-                                </li>
-                            <!--{/if}-->
-                        <!--{/if}-->
-                    <!--{/section}-->
-                </ul>
-            <!--{/strip}-->
+            <!--{include file="`$smarty.const.TEMPLATE_REALDIR`frontparts/bloc/category_tree_fork.tpl" children=$arrTree treeID="categorytreelist"}-->
         </div>
     </div>
Index: branches/version-2_12-dev/data/Smarty/templates/default/frontparts/bloc/category_tree_fork.tpl
===================================================================
--- branches/version-2_12-dev/data/Smarty/templates/default/frontparts/bloc/category_tree_fork.tpl	(revision 22586)
+++ branches/version-2_12-dev/data/Smarty/templates/default/frontparts/bloc/category_tree_fork.tpl	(revision 22586)
@@ -0,0 +1,32 @@
+<!--{*
+ * This file is part of EC-CUBE
+ *
+ * Copyright(c) 2000-2013 LOCKON CO.,LTD. All Rights Reserved.
+ *
+ * http://www.lockon.co.jp/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *}-->
+
+<ul<!--{if $treeID != ""}--> id="<!--{$treeID}-->"<!--{/if}-->>
+<!--{foreach from=$children item=child}-->
+    <li<!--{if !in_array($child.category_id, $arrDispID)}--> style="display: none;"<!--{/if}--> class="level<!--{$child.level}--><!--{if in_array($child.category_id, $tpl_category_id)}--> onmark<!--{/if}-->">
+        <p><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></p>
+        <!--{if isset($child.children|smarty:nodefaults)}-->
+            <!--{include file="`$smarty.const.TEMPLATE_REALDIR`frontparts/bloc/category_tree_fork.tpl" children=$child.children}-->
+        <!--{/if}-->
+    </li>
+<!--{/foreach}-->
+</ul>
