ずっとブロックで作ろうと考えていた「パンくずリスト」。。そんな面倒なことをするよりも、単純に各商品の商品詳細ページで表示してあげたほうが分かりやすいのかもしれない。。
\html\products\detail.php
// パンくずリスト用
$objPage->arrProduct[“parent_category_id”] = lfGetParentCategoryID($objPage->arrProduct[“category_id”]);
$objPage->arrProduct[“root_category_id”] = lfGetRootCategoryID($objPage->arrProduct[“category_id”]);$objPage->category_id = sfGetCategoryId($tmp_id, “”);
$objPage->category_name = $conn->getOne(“SELECT category_name FROM dtb_category WHERE category_id = ?”,array($objPage->category_id));$objPage->parent_category_id = lfGetParentCategoryID($objPage->arrProduct[“category_id”]);
$objPage->parent_category_name = $conn->getOne(“SELECT category_name FROM dtb_category WHERE category_id = ?”,array($objPage->parent_category_id));$objPage->root_category_id = lfGetRootCategoryID($objPage->arrProduct[“category_id”]);
$objPage->root_category_name = $conn->getOne(“SELECT category_name FROM dtb_category WHERE category_id = ?”,array($objPage->root_category_id));
/* 親カテゴリの取得 */
function lfGetParentCategoryID($category_id) {
$objQuery = new SC_Query();
$parent_category_id = $objQuery->get(“dtb_category”, “parent_category_id”, “category_id = ?”, array($category_id));
if($parent_category_id < 1) {
return $category_id;
}
return $parent_category_id;
}/* ルートカテゴリの取得 */
function lfGetRootCategoryID($category_id) {
$objQuery = new SC_Query();
do{
$parent_category_id = $objQuery->get(“dtb_category”, “parent_category_id”, “category_id = ?”, array($category_id));
if($parent_category_id > 0) {
$category_id = $parent_category_id;
}
}while($parent_category_id > 1);
return $category_id;
}
テンプレートの適当な場所に追加
<div class=”fs14″>
<a href=”<!–{$smarty.const.SITE_URL}–>”>HOME</a>
<!–{if $arrProduct.root_category_id != $arrProduct.parent_category_id}–>
≫<a href=”<!–{$smarty.const.URL_DIR}–>products/category_<!–{$arrProduct.root_category_id}–>.html” title=”<!–{$root_category_name}–>”><!–{$root_category_name}–></a>
<!–{/if}–>
<!–{if $arrProduct.parent_category_id != $arrProduct.category_id}–>
≫<a href=”<!–{$smarty.const.URL_DIR}–>products/category_<!–{$arrProduct.parent_category_id}–>.html” title=”<!–{$root_category_name}–>@<!–{$parent_category_name}–>”><!–{$parent_category_name}–></a>
<!–{/if}–>
≫<a href=”<!–{$smarty.const.URL_DIR}–>products/category_<!–{$arrProduct.category_id}–>.html” title=”<!–{$root_category_name}–>@<!–{$parent_category_name}–>@<!–{$category_name}–>”><!–{$category_name}–></a>
</div>
まぁ。。。覚書程度