aska824様にインスパイアされて、ちょっとだけ手直しした第二弾を作ってみましたヨ。
コンセプトは、少しだけSmartyテンプレ側でHTMLを処理するようにしたのと、全ページにパンくずリストが出るようにしてみました。
ちょっとpatapata様風味も入れつつって感じです。
./data/class/pages/products/LC_Page_Products_List.php の action() 内の末尾に以下のコードを記述
//パンくずリストを取得
$this->arrTopicPath = $this->lfTopicPath($this->mode, $this->arrForm['category_id'], $this->arrForm['name']);
./data/class/pages/products/LC_Page_Products_List.php の LC_Page_Products_List クラス内の末尾に以下のコードを記述
/**
* パンくずリストを設定
*
* @return array
*/
function lfTopicPath($mode, $category_id, $category_name){
if ($mode == 'search') {
$arrRet = $category_name . " の検索結果";
} elseif (empty($category_id)){
$arrRet = "全商品";
} else {
$objDb = new SC_Helper_DB_Ex();
$arrCatId = $objDb->sfGetParents("dtb_category", "parent_category_id", "category_id", $category_id);
foreach($arrCatId as $key => $val){
$arrCatName = $objDb->sfGetCat($val);
if($val != $category_id){
$arrRet[] = '<a href="./list.php?category_id=' .$val. '">'. $arrCatName['name'] . '</a> > ';
} else {
$arrRet[] = $arrCatName['name'];
}
}
}
return $arrRet;
}
./data/class/pages/products/LC_Page_Products_Detail.php の action() 内の末尾に以下のコードを記述
// パンくずリストを取得
$this->arrTopicPath = $this->lfTopicPath2($product_id);
./data/class/pages/products/LC_Page_Products_List.php の LC_Page_Products_Detail クラス内の末尾に以下のコードを記述
/*
* パンくずリストを設定
* @return array
*/
function lfTopicPath2($product_id){
$objDb = new SC_Helper_DB_Ex();
$arrCategory_id = $objDb->sfGetCategoryId($product_id);
$arrCatId = $objDb->sfGetParents("dtb_category", "parent_category_id", "category_id", $arrCategory_id[0]);
foreach($arrCatId as $key => $val){
$arrCatName = $objDb->sfGetCat($val);
$arrRet[] = '<a href="./list.php?category_id=' .$val. '">'. $arrCatName['name'] . '</a> > ';
}
$arrRet[] = $this->arrProduct['name'];
return $arrRet;
}
./data/Smarty/templates/default/site_main.tpl の適当な場所に以下のタグを記述
<!--{* ▼BREAD CRUMBS *}-->
<!--{if $smarty.server.PHP_SELF != '/index.php'}-->
<p><a href="<!--{$smarty.const.HTTP_URL}-->">TopPage</a> >
<!--{if $arrTopicPath}-->
<!--{foreach from=$arrTopicPath item=Topic}-->
<!--{$Topic}-->
<!--{/foreach}-->
<!--{else}--><!--{$tpl_title|h}-->
<!--{/if}-->
</p>
<!--{/if}-->
<!--{* ▲BREAD CRUMBS *}-->
追記:バグ発見したので 6/12 20:00 にコード変更しました。