アットウィキロゴ

子カテゴリを表示するブロックの生成

管理画面から、
subcategory.tpl を作成します。

引用:


<!--商品カテゴリーここから-->
<div id="maincate">
<h2><!--{$maincate[0].category_name }--></h2>
<div class="maincate_disp">
<!--{$maincate[0].category_disp }-->
</div>
<ul>
<!--{section name=cnt loop=$arrTree}-->
<!--{* 階層を level へ *}-->
<!--{assign var=level value="`$arrTree[cnt].level`}-->
<!--{* カテゴリ名を disp_name へ *}-->
<!--{assign var=disp_name value="`$arrTree[cnt].category_name`"}-->
<!--{assign var=disp_disp value="`$arrTree[cnt].category_disp`"}-->
<!--{* 表示カテゴリのみ *}-->
<!--{if $arrTree[cnt].display == 1}-->
<!--{* 選択したカテゴリ *}-->
<!--{if in_array($arrTree[cnt].category_id, $tpl_category_id) }-->
<li><a href="<!--{$smarty.const.URL_DIR}-->products/list.php?category_id=<!--{$arrTree[cnt].category_id}-->" title="<!--{$disp_name|escape}-->"><!--{$disp_name|escape}--></a></li>

<!--{* 未選択カテゴリ *}-->
<!--{else}-->
<li><a href="<!--{$smarty.const.URL_DIR}-->products/list.php?category_id=<!--{$arrTree[cnt].category_id}-->" title="<!--{$disp_name|escape}-->"><!--{$disp_name|escape}--></a></li>
<!--{/if}-->

<!--{$disp_disp|sfCutString:40|escape}-->

<!--{/if}-->
<!--{/section}-->
</ul>
</div>
<!--商品カテゴリーここまで-->





ランキングブロック作成と同じ要領で、
データベースで、
dtb_blocに追加された
subcategory.tpl の php_path を下記のように編集します。

frontparts/bloc/subcategory.php


次に、
/html/frontparts/blocに
subcategory.phpを作成してアップロード

category.phpをコピーして、作成します。
内容は下記のとおりです。

引用:


<?php

require_once(CLASS_EX_PATH . "page_extends/frontparts/bloc/LC_Page_FrontParts_Bloc_Subcategory.php");


$objPage = new LC_Page_FrontParts_BLoc_Subcategory();
register_shutdown_function(array($objPage, "destroy"));
$objPage->init();
$objPage->process();
?>




次に、
/data/class_extends/page_extends/frontparts/bloc に、

LC_Page_FrontParts_Bloc_Subcategory.php
を作成してアップロードします。

引用:


<?php

class LC_Page_FrontParts_Bloc_Subcategory extends LC_Page_FrontParts_Bloc {


/**

Page を初期化する.

*

@return void

/

function init() {
parent::init();
$bloc_file = 'subcategory.tpl';
$this->setTplMainpage($bloc_file);
}

/**

Page のプロセス.

*

@return void

/

function process() {
$objSubView = new SC_SiteView();
$objDb = new SC_Helper_DB_Ex();

$arrCategory_id = $objDb->sfGetCategoryId($_GET['product_id'], $_GET['category_id']);

$this->tpl_category_id = empty($arrCategory_id) ? array(0) : $arrCategory_id;
if($arrCategory_id[0]){
$this->lfGetCatdate($arrCategory_id[0], true, $this);
$this->lfGetCatTree($this->tpl_category_id, true, $this);
}

$objSubView->assignobj($this);
$objSubView->display($this->tpl_mainpage);
}

/**

モバイルページを初期化する.

*

@return void

/

function mobileInit() {
$this->tpl_mainpage = MOBILE_TEMPLATE_DIR . "frontparts/"
. BLOC_DIR . 'category.tpl';
}

/**

Page のプロセス(モバイル).

*

@return void

/

function mobileProcess() {
$objSubView = new SC_MobileView();

$this->lfGetMainCat(true, $this);

$objSubView->assignobj($this);
$objSubView->display($this->tpl_mainpage);
}

/**

デストラクタ.

*

@return void

/

function destroy() {
parent::destroy();
}

function lfGetCatTree($arrParent_category_id, $count_check = false) {
$objQuery = new SC_Query();
$objDb = new SC_Helper_DB_Ex();
$col = "*";
$from = "dtb_category";
$where = "del_flg = 0 AND parent_category_id =".$arrParent_category_id[0];
$objQuery->setoption("ORDER BY rank DESC");
$arrRet = $objQuery->select($col, $from, $where);

foreach ($arrParent_category_id as $category_id) {
$arrParentID = $objDb->sfGetParents($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $category_id);
$arrBrothersID = SC_Utils_Ex::sfGetBrothersArray($arrRet, 'parent_category_id', 'category_id', $arrParentID);
$arrChildrenID = SC_Utils_Ex::sfGetUnderChildrenArray($arrRet, 'parent_category_id', 'category_id', $category_id);

$this->root_parent_id[] = $arrParentID[0];

$arrDispID = array_merge($arrBrothersID, $arrChildrenID);

foreach($arrRet as $key => $array) {
foreach($arrDispID as $val) {
if($array['category_id'] == $val) {
$arrRet[$key]['display'] = 1;
break;
}
}
}
}

$this->arrTree = $arrRet;
}

function lfGetMainCat($count_check = false, &$objSubPage) {
$objQuery = new SC_Query();
$col = "*";
$from = "dtb_category left join dtb_category_total_count using (category_id)";
$where = 'level <= 2 AND del_flg = 0';
if($count_check) {
$where .= " AND product_count > 0";
}
$objQuery->setoption("ORDER BY rank DESC");
$arrRet = $objQuery->select($col, $from, $where);

$arrMainCat = array();
foreach ($arrRet as $cat) {
if ($cat['level'] != 1) {
continue;
}

$arrChildrenID = SC_Utils_Ex::sfGetUnderChildrenArray($arrRet, 'parent_category_id', 'category_id', $cat['category_id']);
$cat['has_children'] = count($arrChildrenID) > 0;
$arrMainCat[] = $cat;
}

$objSubPage->arrCat = $arrMainCat;
return $objSubPage;
}

function lfGetCatdate($arrCategory_id, $count_check = false){
$objQuery = new SC_Query();
$objDb = new SC_Helper_DB_Ex();
$col = "*";
$from = "dtb_category";
$where = "del_flg = 0 AND category_id = ".$arrCategory_id;
$objQuery->setoption("ORDER BY rank DESC");
$arrRet = $objQuery->select($col, $from, $where);
$this->maincate = $arrRet;
}
}
?>






とりあえず、以上の作業で、
子カテゴリーが別ブロックで表示されるようになりました。

あとは、CSSでデザインを整えてください。
最終更新:2009年10月20日 16:53
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。