sakurai07 さん
どこが間違っているかはちょっと分からなかったので、
手順をざっくりまとめてみました。
※【追記】幾つか誤っている手順がありましたので、変更して投稿しなおしました。(修正部分を赤字にしています)
恐らく、問題になっているのは赤字で記している部分周りではないかと考えています。よかったら、この手順に沿ってもう一度確認してみてください。
【Step.1】新着レビューブロックを作成
管理画面(デザイン管理→ブロック編集)から、
・ブロック名:「NEW REVIEW」(←分かればなんでも良いが、後ほどphpMyAdminで確認する時に文字化けする場合があるので英語表記にしておく)
・ファイル名:「view」(view.tpl)
としてブロックを新規作成。
ブロックの内容は、「新着情報」(news.tpl)を基に、以下の様にする。
<!--{*
* This file is part of EC-CUBE
* (説明のため、ライセンス表記部分は省略しています)
*}-->
<div id="newsarea">
<h2>
<img src="<!--{$TPL_DIR}-->img/top/news.jpg" width="400" height="29" alt="新着レビュー" />
</h2>
<p>☆★☆ 新着レビューブロックです★☆★</p>
<!--{section name=data loop=$arrNews}-->
<dl>
<dt><!--{$arrNews[data].review_date_disp|date_format:"%Y/%m/%d"}--></dt>
<dd>
<a href="<!--{$smarty.const.URL_DIR}-->products/detail.php?product_id=<!--{$arrNews[data].product_id}-->">
<!--{$arrNews[data].title|escape|nl2br}-->
</a><br />
by <!--{$arrNews[data].reviewer_name|escape|nl2br}-->さん(★<!--{$arrNews[data].recommend_level|escape|nl2br}-->つ)<br />
<!--{$arrNews[data].comment|escape|nl2br}-->
</dd>
</dl>
<!--{/section}-->
</div>
(ファイルは、 html/user_data/packages/default/bloc/view.tpl として作成されています)
【Step.2】view.phpの作成
クラスの名前を、以下の通り変更しています。
・LC_Page_FrontParts_Bloc_view → LC_Page_FrontParts_Bloc_Review
・LC_Page_FrontParts_Bloc_view_Ex → LC_Page_FrontParts_Bloc_Review_Exhtml/frontparts/bloc/news.phpをコピーして、
view.phpを作成し、内容を以下の通り変更する。
■requireの変更
require_once(CLASS_EX_PATH . "page_extends/frontparts/bloc/LC_Page_FrontParts_Bloc_News_Ex.php");
↓↓↓
require_once(CLASS_EX_PATH . "page_extends/frontparts/bloc/LC_Page_FrontParts_Bloc_Review_Ex.php");
■利用するクラスの変更$objPage = new LC_Page_FrontParts_BLoc_News_Ex();
↓↓↓
$objPage = new LC_Page_FrontParts_BLoc_Review_Ex();
【Step.3】(view.phpから読み込まれる)LC_Page_FrontParts_Bloc_Review_Ex.phpの作成
data/class_extends/page_extends/frontparts/bloc/LC_Page_FrontParts_Bloc_News_Ex.phpをコピーして
LC_Page_FrontParts_Bloc_Review_Ex.phpを作成し、内容を以下の通り変更する。
■requireの変更
require_once(CLASS_PATH . "pages/frontparts/bloc/LC_Page_FrontParts_Bloc_News.php");
↓↓↓
require_once(CLASS_PATH . "pages/frontparts/bloc/LC_Page_FrontParts_Bloc_Review.php");
■クラス定義の変更class LC_Page_FrontParts_Bloc_News_Ex extends LC_Page_FrontParts_Bloc_News {
↓↓↓
class LC_Page_FrontParts_Bloc_Review_Ex extends LC_Page_FrontParts_Bloc_Review {
【Step.4】(LC_Page_FrontParts_Bloc_Review_Ex.phpから読み込まれる)LC_Page_FrontParts_Bloc_Review.phpの作成
data/class/pages/frontparts/bloc/LC_Page_FrontParts_Bloc_news.phpをコピーして
LC_Page_FrontParts_Bloc_Review.phpを作成し、内容を以下の通り変更する。
■クラス定義の変更class LC_Page_FrontParts_Bloc_News extends LC_Page_FrontParts_Bloc {
↓↓↓
class LC_Page_FrontParts_Bloc_Review extends LC_Page_FrontParts_Bloc {
■news.tpl→view.tpl
function init() {
parent::init();
$bloc_file = 'news.tpl';
$this->setTplMainpage($bloc_file);
}
↓↓↓
function init() {
parent::init();
$bloc_file = 'view.tpl';
$this->setTplMainpage($bloc_file);
}
■lfGetNews() → lfGetReview()
//新着情報取得
$this->arrNews = $this->lfGetNews();
↓↓↓
//新着コメント一覧取得
$this->arrNews = $this->lfGetReview();
■SQL変更(新着レビューを最大5件まで表示させる)
function lfGetNews(){
$conn = new SC_DBConn();
$sql = "SELECT *, cast(news_date as date) as news_date_disp FROM dtb_news WHERE del_flg = '0' ORDER BY rank DESC";
$list_data = $conn->getAll($sql);
return $list_data;
}
↓↓↓
function lfGetReview(){
$conn = new SC_DBConn();
$sql = "SELECT *, cast(create_date as date) as review_date_disp FROM dtb_review WHERE del_flg = '0' AND status = '1' ORDER BY create_date DESC LIMIT 5";
$list_data = $conn->getAll($sql);
return $list_data;
}
【Step.5】新着レビューブロックと、view.phpを結びつける
DBのデータを変更するツール(phpMyAdminなど)を利用して、
「dtb_bloc」テーブルの、filenameが「view」(bloc_nameが「NEW REVIEW」)のレコードについて、
php_pathを「frontparts/bloc/view.php」にする。
これで、「NEW REVIEW」ブロック表示時に、以下のファイルが読み込まれる様になります。
html/frontparts/bloc/view.php
【Step.6】新着レビューブロックをページに配置する
管理画面(デザイン管理→レイアウト編集)で、「NEW REVIEW」ブロックをページに配置する。
以上です。
これで、新着レビューブロックを配置したページに、新着レビューが表示されると思います。
----------------
株式会社システムフレンド
羽生 賢太郎(Kentaro Habu)
改造専門店・EC-CUBE工房