バージョン選択

フォーラム

メニュー

オンライン状況

68 人のユーザが現在オンラインです。 (56 人のユーザが フォーラム を参照しています。)
登録ユーザ: 1
ゲスト: 67
wdev7969 もっと...

サイト内検索

その他 > その他 > パンくずリストの表示

その他

新規スレッドを追加する

スレッド表示 | 古いものから 前のトピック | 次のトピック | 下へ
投稿者 スレッド
ゲスト
投稿日時: 2007/10/25 15:21
対応状況: −−−
Re: パンくずリストの表示
To:pinerayさん

ご回答頂き有難うございます。
恥ずかしながらsfGetCategoryIdの処理自体が良くわかっていなかったので
pinerayさんのご指摘からsfGetCategoryIdのファンクションをもう一度良く見てみましたが、一つ目の引数が空ではカテゴリIDを取得できない場合があるんですね、、、

パンくずリストの追加でサイトの操作性も格段に良くなりました、有難うございました。
pineray
投稿日時: 2007/10/25 12:18
対応状況: −−−
長老
登録日: 2006/9/9
居住地: 伊賀
投稿: 292
Re: パンくずリストの表示
お役に立てて光栄です

商品詳細ページで使用する場合は、以下のようにすれば正しく$category_idを取得できるのではないでしょうか。
$category_id = sfGetCategoryId($tmp_id, $_GET['category_id']);
$objPage = lfGetBreadcrumb($category_id, false, $objPage);
$_GETでカテゴリIDが指定されていない場合に、商品IDからカテゴリIDを取得します。
sikao
投稿日時: 2007/10/25 11:49
対応状況: −−−
新米
登録日: 2007/8/28
居住地:
投稿: 4
Re: パンくずリストの表示
pinerayさんの投稿を元にパンくず機能を追加してみました。
商品一覧・詳細ページでも問題なく使えて非常に重宝しております。ありがとうございます。

ちなみに商品詳細ページで使う場合は
detail.phpの100行目あたりに

$category_id = sfGetCategoryId("", $_GET['category_id']);
$objPage = lfGetBreadcrumb($category_id, false, $objPage);

上記のコードを追加して、detail.tplの方でもパンくずを利用していますが、
1行目の $category_id への値の入れ方が正しいのかどうかが良く分かっていないので、
どなたかご指摘頂けましたら幸いです、、、
pineray
投稿日時: 2007/10/16 15:44
対応状況: −−−
長老
登録日: 2006/9/9
居住地: 伊賀
投稿: 292
Re: パンくずリストの表示
自分なりの方法で、一覧ページにパンくずリストを表示できましたので、知識共有のために投稿しておきます。
少し変更すれば商品詳細ページにも利用できると思います。
カスタマイズしたEC-CUBEのバージョンは1.3.4正式版です。

まず、list.phpの142行目あたりに赤字の部分を追加
$objPage->category_id = $category_id;
$objPage->arrSearch = $arrSearch;
$objPage = lfGetBreadcrumb($category_id, false, $objPage);

sfCustomDisplay($objPage);

次に、同じくlist.phpの最後のほう、ローカル関数に追加
// パンくずリストの取得
function lfGetBreadcrumb($child_category_id, $count_check = false, $objPage) {
	$objQuery = new SC_Query();
	$col = "*";
	$from = "dtb_category left join dtb_category_total_count using (category_id)";
	// 登録商品数のチェック
	if($count_check) {
		$where = "del_flg = 0 AND product_count > 0";
	} else {
		$where = "del_flg = 0";
	}
	$objQuery->setoption("ORDER BY rank DESC");
	$arrRet = $objQuery->select($col, $from, $where);

	$arrDispID = sfGetParentsArray('dtb_category', 'parent_category_id', 'category_id', $child_category_id);

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

	$objPage->arrBreadcrumb = $arrBreadcrumb;
	return $objPage;
}

そして、list.tplの好きな場所に追加
<!--{if $category_id}-->
	<!-- パンくずリスト -->
	<!--{section name=cnt loop=$arrBreadcrumb}-->
		<a href="<!--{$smarty.const.URL_DIR}-->products/list.php?category_id=<!--{$arrBreadcrumb[cnt].category_id}-->"><!--{$arrBreadcrumb[cnt].category_name|sfCutString:20|escape}--></a>
		<!--{if !$smarty.section.cnt.last}--> > <!--{/if}-->
	<!--{/section}-->
<!--{/if}-->
ryo
投稿日時: 2007/8/17 19:28
対応状況: −−−
一人前
登録日: 2007/7/26
居住地: 関西
投稿: 86
Re: パンくずリストの表示
あれま、ダメでしたか

表示が出来ていないと言うことは、値の取得が出来ていないと思うので、tpl側ではなくphp側の問題だと思います。

ちなみに、どこまで取得できていないのでしょうか?
引用:
$objPage->arrProduct["parent_category_id"] = lfGetParentCategoryID($category_id);

この辺のIDから取得できていないのか、
引用:
$objPage->arrProduct["root_category_name"] =
$conn->getOne("SELECT category_name FROM dtb_category WHERE category_id =
?",array($objPage->arrProduct["root_category_id"]));

この辺の名前の取得が出来ていないのか。
(まぁ、カテゴリ名が表示されていない時点で、こちらは取得できていないけど・・・)

一度、tpl側で
引用:
<!--{$category_id}-->


引用:
<!--{$arrProduct.parent_category_id}-->


引用:
<!--{$arrProduct.grandparent_category_id}-->


引用:
<!--{$arrProduct.root_category_id}-->

の値を表示してみて、カテゴリIDが表示されているかどうか確認してみてください。
IDが取得できているのなら、その後の名前の取得で失敗していると思うので。


----------------
/* Ryo from KANSAI */
まいどっ!

NSX
投稿日時: 2007/8/17 14:16
対応状況: −−−
常連
登録日: 2007/7/31
居住地:
投稿: 61
Re: パンくずリストの表示
こんにちは!

早速ソースの追加しましたが、、
残念です、TOP>>とは出るのですが、後ろが表示されませんでした。

http://usmc.jp/
のような状態です。

どうもありがとうございました。

できれば、他触った箇所などは覚えてないですかネ。^_^;

NSX
投稿日時: 2007/8/17 13:57
対応状況: −−−
常連
登録日: 2007/7/31
居住地:
投稿: 61
Re: パンくずリストの表示
ryoさん

こんにちは、どうもありがとうございます。

長いソースをコピーしたりして、お手間を取らせてしまいました。

それでは早速チャレンジしますね。
ryo
投稿日時: 2007/8/17 13:26
対応状況: −−−
一人前
登録日: 2007/7/26
居住地: 関西
投稿: 86
Re: パンくずリストの表示
随分いじったので、元からどこを変えたのかちょっと忘れたのですが、恐らく以下の方法だと思います。(本当に恥ずかしいくらい稚拙なソースですが)

まず、/html/products/list.phpの140行目あたりに以下の文を入れてます。(はっきりいって場所はどこでもいいはずです。)

引用:

// パンくずリスト用値取得(かなり強引。4階層まで対応)
// 親カテゴリID取得

$objPage->arrProduct["parent_category_id"] =
lfGetParentCategoryID($category_id);
// 今取得した親カテゴリの親カテゴリIDを取得
$objPage->arrProduct["grandparent_category_id"] =
lfGetParentCategoryID($objPage->arrProduct["parent_category_id"]);
// ルートカテゴリIDを取得
$objPage->arrProduct["root_category_id"] =
lfGetRootCategoryID($category_id);

// ルートカテゴリ名を取得
$objPage->arrProduct["root_category_name"] =
$conn->getOne("SELECT category_name FROM dtb_category WHERE category_id = ?",array($objPage->arrProduct["root_category_id"]));
// 親の親のカテゴリ名を取得
$objPage->arrProduct["grandparent_category_name"] =
$conn->getOne("SELECT category_name FROM dtb_category WHERE category_id = ?",array($objPage->arrProduct["grandparent_category_id"]));
// 親カテゴリ名を取得
$objPage->arrProduct["parent_category_name"] =
$conn->getOne("SELECT category_name FROM dtb_category WHERE category_id = ?",array($objPage->arrProduct["parent_category_id"]));
// 現在のカテゴリ名を取得
$objPage->arrProduct["current_category_name"] =
$conn->getOne("SELECT category_name FROM dtb_category WHERE category_id = ?",array($category_id));


そのphpの最後の方の関数群に以下の関数を追加
引用:

/* 親カテゴリの取得 */
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;
}


後は、/html/user_data/templates/list.tplのパンくずリストを表示したい場所に以下を追加します。
(ココが最強に強引。もっとシンプルに記述できるかも?)

引用:

<!--{*パンくずリスト開始*}-->
<div id="pankuzu">
<a href="<!--{$smarty.const.SITE_URL}-->">TOP</a> >

<!--{if $category_id == $arrProduct.parent_category_id && $arrProduct.parent_category_id == $arrProduct.grandparent_category_id && $category_id == $arrProduct.root_category_id}-->
<!--{elseif $category_id != $arrProduct.parent_category_id && $arrProduct.parent_category_id == $arrProduct.grandparent_category_id && $arrProduct.grandparent_category_id == $arrProduct.root_category_id}-->
<a href="<!--{$smarty.const.SITE_URL}-->products/list.php?category_id=
<!--{$arrProduct.root_category_id}-->">
<!--{$arrProduct.root_category_name}--></a> >

<!--{elseif $category_id != $arrProduct.parent_category_id && $arrProduct.parent_category_id != $arrProduct.grandparent_category_id && $arrProduct.grandparent_category_id == $arrProduct.root_category_id}-->
<a href="<!--{$smarty.const.SITE_URL}-->products/list.php?category_id=
<!--{$arrProduct.root_category_id}-->">
<!--{$arrProduct.root_category_name}--></a> >
<a href="<!--{$smarty.const.SITE_URL}-->products/list.php?category_id=
<!--{$arrProduct.parent_category_id}-->">
<!--{$arrProduct.parent_category_name}--></a> >

<!--{else}-->
<a href="<!--{$smarty.const.SITE_URL}-->products/list.php?category_id=
<!--{$arrProduct.root_category_id}-->">
<!--{$arrProduct.root_category_name}--></a> >
<a href="<!--{$smarty.const.SITE_URL}-->products/list.php?category_id=
<!--{$arrProduct.grandparent_category_id}-->">
<!--{$arrProduct.grandparent_category_name}--></a> >
<a href="<!--{$smarty.const.SITE_URL}-->products/list.php?category_id=
<!--{$arrProduct.parent_category_id}-->">
<!--{$arrProduct.parent_category_name}--></a> >

<!--{/if}-->
// 以下は検索の場合、「検索結果」というタイトルの代わりに検索文字列でパンくずリストを作るための処理です。
必要な場合記述。必要なければcategory_nameだけでいいかも。

<!--{if $tpl_subtitle == "検索結果"}-->
<!--{$arrSearch.name|escape}-->
<!--{else}-->
<!--{$arrProduct.current_category_name}-->
<!--{/if}-->
</div>
<!--{*パンくずリスト終了*}-->

青字・・・コメント
黒字・・・PHPスクリプト
緑字・・・HTML表示部分


これでOKだと思うんですが、ダメだったらごめんなさい。
他にもいじってるところがあるんだと思いますw

同じように親の親の親の・・・とすればもう1階層増やすことも恐らく可能でしょう。


----------------
/* Ryo from KANSAI */
まいどっ!

NSX
投稿日時: 2007/8/17 12:35
対応状況: −−−
常連
登録日: 2007/7/31
居住地:
投稿: 61
Re: パンくずリストの表示
ryoさん

こんにちは!
listも表示できているんですね!

>強引すぎてここでソース晒すの恥ずかしいので止めと来ます(笑)

そんな事おっしゃらずに是非とも、ソースを見せていただけませんでしょうか?

どうぞよろしくお願いしますm(_ _)m
ryo
投稿日時: 2007/8/17 11:51
対応状況: −−−
一人前
登録日: 2007/7/26
居住地: 関西
投稿: 86
Re: パンくずリストの表示
僕は「親カテゴリを表示」を利用して、親の親を取得するように設定し、

top > root > 親の親 > 親 > 現在

と4階層まで対応しています。
かなり強引なんですけどね・・・

listとdetailの両方でパンくずの表示に成功してます。
強引すぎてここでソース晒すの恥ずかしいので止めと来ます(笑)

やろうと思えば最大の5階層まで対応できると思いますが、現在作成中のサイトでは必要ないので4階層で止めてます。


----------------
/* Ryo from KANSAI */
まいどっ!

(1) 2 3 »
スレッド表示 | 古いものから 前のトピック | 次のトピック | トップ


 



ログイン


EC-CUBE公式 Amazon Payプラグイン

統計情報

総メンバー数は89,033名です
総投稿数は110,020件です

投稿数ランキング

1
seasoft
7367
2
468
3217
3
AMUAMU
2712
4
nanasess
2314
5
umebius
2085
6
yuh
1819
7
h_tanaka
1646
8
red
1570
9
mcontact
1296
10
tsuji
958
11
fukap
907
12
shutta
835
13
tao_s
799
14 ramrun 789
15 karin 689
16 sumida 641
17
homan
633
18 DELIGHT 572
19
patapata
502
20
flealog
485


ネットショップの壺

EC-CUBEインテグレートパートナー

Copyright© EC-CUBE CO.,LTD. All Rights Reserved.