EC CUBEでカテゴリーの最大階層を増やす
2009 年 4 月 21 日 火曜日EC CUBEはデフォルトでカテゴリーの最大階層が5に指定されている。これを増やすにはパラメーター設定のLEVEL_MAXの数値を変更すれば良い。
カテゴリーを細分化したい場合、特にSEO対策などを念頭におく場合には数値の変更。
EC CUBEはデフォルトでカテゴリーの最大階層が5に指定されている。これを増やすにはパラメーター設定のLEVEL_MAXの数値を変更すれば良い。
カテゴリーを細分化したい場合、特にSEO対策などを念頭におく場合には数値の変更。
ソースそのものを以下のサイトを参考
www.gnnk.net
web book movie
[EC-CUBE]パンくずリスト
バージョンが古いのか、上記サイトの指示に従ってソースを埋めても動作しなかったので、以下覚書。
なお、以下の行数はEC CUBE version 2.3.4
/data/class_extends/helper_extends/SC_Helper_DB_Ex.php
37行目に以下を追加function sfGetTopicPath($category_id){
// 商品が属するカテゴリIDを縦に取得
$objQuery = new SC_Query();
$arrCatID = $this->sfGetParents($objQuery, "dtb_category", "parent_category_id", "category_id", $category_id);
$TopicPath = " > ";// カテゴリー名称を取得する
foreach($arrCatID as $key => $val){
$sql = "SELECT category_name FROM dtb_category WHERE category_id = ?";
$arrVal = array($val);
$CatName = $objQuery->getOne($sql,$arrVal);
if( $val != $category_id){
$TopicPath .= '<a href="./list.php?category_id=' .$val . '">' . $CatName . '</a> > ';
}else{
$TopicPath .= $CatName;
}
}return $TopicPath;
}
function sfGetTopicPath2($category_id){
// 商品が属するカテゴリIDを縦に取得
$objQuery = new SC_Query();
$arrCatID = $this->sfGetParents($objQuery, "dtb_category", "parent_category_id", "category_id", $category_id);
$TopicPath = " > ";// カテゴリー名称を取得する
foreach($arrCatID as $key => $val){
$sql = "SELECT category_name FROM dtb_category WHERE category_id = ?";
$arrVal = array($val);
$CatName = $objQuery->getOne($sql,$arrVal);
$TopicPath .= '<a href="./list.php?category_id=' .$val . '">' . $CatName . '</a> > ';
}
return $TopicPath;
}
これは指定通りに、{}の中に埋め込む。
/data/class/pages/products/LC_Page_Products_List.php
107行目に以下を追加
$TopicPath = $objDb->sfGetTopicPath($arrCategory_id[0]);
$this->tpl_topicpath = $TopicPath;
こちらは107行目ではなく113行目
/data/class/pages/products/LC_Page_Products_Detail.php
211行目に以下を追加$arrTopicPath = $objDb->sfGetTopicPath2($arrCategory_id[0]);
$this->tpl_topicpath = $arrTopicPath;
これは211行目ではなく231行目
/data/Smarty/templates/default/site_main.tpl
37行目に以下を追加<!–{if $tpl_topicpath != ""}–>
<a href="<!–{$smarty.const.SITE_URL}–>index.php">TopPage</a>
<!–{$tpl_topicpath}–>
<!–{$arrProduct.name|escape}–>
<!–{/if}–>
これは、設置した場所であれば、指定以外(detail.phpやlist.php)でも可。
ただし、URLを静的化している場合でも、発行されるURLは動的(list.php?category=***の形)になる。
EC CUBEはデフォルトではタイトルまわりが、SEO的にもユーザービリティ的も良くは感じない。
site_frame.tplを以下のように変更
<!–{assign var=index value="`$smarty.const.URL_DIR`index.php"}–>
<!–{if $smarty.server.PHP_SELF==$index}–>
<title><!–{$arrSiteInfo.shop_name}–></title>
<!–{elseif $tpl_title == "商品一覧ページ"}–>
<title><!–{$tpl_subtitle|escape}–> : <!–{$arrSiteInfo.shop_name}–></title>
<!–{else}–>
<title><!–{$tpl_title|escape}–> : <!–{$arrSiteInfo.shop_name}–></title>
<!–{/if}–>
商品一覧ページでは最上階のカテゴリを表示
EC CUBEの><!–{$tpl_title|escape}–>は商品詳細ページに 商品詳細 タイトル と出力するので、SEO対策にとっても、ユーザ-にとっても邪魔な存在。
そこでclass/pages/products/LC_Page_Products_Detail.phpの中の254行目を以下のように変更する。
$this->tpl_title = "商品詳細 ". $this->arrProduct["name"];
↓
$this->tpl_title = $this->arrProduct["name"];
これで<!–{$tpl_title|escape}–>を用いても、商品詳細の文字は出力されなくなる。
siteframe.tplにある、siteframe.tpl
<!–{assign var=index value="`$smarty.const.URL_DIR`index.php"}–>
<!–{if $smarty.server.PHP_SELF==$index}–>
<title><!–{$arrSiteInfo.shop_name}–></title>
<!–{else}–>
<title><!–{$tpl_title|escape}–>:<!–{$arrSiteInfo.shop_name|escape}–></title>
<!–{assign var=index value="`$smarty.const.URL_DIR`index.php"}–>
<!–{if $smarty.server.PHP_SELF==$index}–>
<title><!–{$arrSiteInfo.shop_name}–></title>
<!–{else}–>
<title><!–{$tpl_title|escape}–>:<!–{$arrSiteInfo.shop_name}–></title>
<!–{/if}–>
mod_rewrite(.htaccess)を用いて動的生成を静的化した上で以下の箇所を変更。
商品一覧ページ
◆対象URL:http://URL/products/list.php
<!–★商品名★–>
【変更前】
<h2><a href="<!–{$smarty.const.DETAIL_P_HTML}–><!–{$arrProducts[cnt].product_id}–>"><!–{$arrProducts[cnt].name|escape}–></a></h2>
↓
【変更後】
<h2><a href="detail<!–{$arrProducts[cnt].product_id}–>.html"><!–{$arrProducts[cnt].name|escape}–></a></h2>
【注意】mod_rewrite(.htaccess)を用いていないと上記タグを変更しても意味がありません。