前回は、新着情報詳細ページ作成をやってみましたが、今回はその続編ということで、
新着情報一覧ページ作成にチャレンジしたいと思います。
PC用ページとして作成してみました。
1.html/news/list.php を新規作成
1 | <?php |
2 | /* |
3 | * This file is part of EC-CUBE |
4 | * |
5 | * Copyright(c) 2000-2012 LOCKON CO.,LTD. All Rights Reserved. |
6 | * |
7 | * http://www.lockon.co.jp/ |
8 | * |
9 | * This program is free software; you can redistribute it and/or |
10 | * modify it under the terms of the GNU General Public License |
11 | * as published by the Free Software Foundation; either version 2 |
12 | * of the License, or (at your option) any later version. |
13 | * |
14 | * This program is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | * GNU General Public License for more details. |
18 | * |
19 | * You should have received a copy of the GNU General Public License |
20 | * along with this program; if not, write to the Free Software |
21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
22 | */ |
23 |
24 | // {{{ requires |
25 | require_once '../require.php' ; |
26 | require_once CLASS_EX_REALDIR . 'page_extends/news/LC_Page_News_List_Ex.php' ; |
27 |
28 | // }}} |
29 | // {{{ generate page |
30 |
31 | $objPage = new LC_Page_News_List_Ex(); |
32 | register_shutdown_function( array ( $objPage , 'destroy' )); |
33 | $objPage ->init(); |
34 | $objPage ->process(); |
2.data/class_extends/page_extends/news/LC_Page_News_List_Ex.php を新規作成
1 | <?php |
2 | /* |
3 | * This file is part of EC-CUBE |
4 | * |
5 | * Copyright(c) 2000-2012 LOCKON CO.,LTD. All Rights Reserved. |
6 | * |
7 | * http://www.lockon.co.jp/ |
8 | * |
9 | * This program is free software; you can redistribute it and/or |
10 | * modify it under the terms of the GNU General Public License |
11 | * as published by the Free Software Foundation; either version 2 |
12 | * of the License, or (at your option) any later version. |
13 | * |
14 | * This program is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | * GNU General Public License for more details. |
18 | * |
19 | * You should have received a copy of the GNU General Public License |
20 | * along with this program; if not, write to the Free Software |
21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
22 | */ |
23 |
24 | // {{{ requires |
25 | require_once CLASS_REALDIR . 'pages/news/LC_Page_News_List.php' ; |
26 |
27 | /** |
28 | e LC_Page_News_List のページクラス(拡張). |
29 | * |
30 | * LC_Page_News_List をカスタマイズする場合はこのクラスを編集する. |
31 | * |
32 | * @package Page |
33 | * @author LOCKON CO.,LTD. |
34 | * @version $Id: LC_Page_Products_List_Ex.php 21867 2012-05-30 07:37:01Z nakanishi $ |
35 | */ |
36 | class LC_Page_News_List_Ex extends LC_Page_News_List { |
37 |
38 | // }}} |
39 | // {{{ nunctions |
40 |
41 | /** |
42 | * Page を初期化する. |
43 | * |
44 | * @return void |
45 | */ |
46 | function init() { |
47 | parent::init(); |
48 | } |
49 |
50 | /** |
51 | * Page のプロセス. |
52 | * |
53 | * @return void |
54 | */ |
55 | function process() { |
56 | parent::process(); |
57 | } |
58 |
59 | /** |
60 | * デストラクタ. |
61 | * |
62 | * @return void |
63 | */ |
64 | function destroy() { |
65 | parent::destroy(); |
66 | } |
67 | } |
3.data/class/pages/news/LC_Page_News_List.php を新規作成
1 | <?php |
2 | /* |
3 | * This file is part of EC-CUBE |
4 | * |
5 | * Copyright(c) 2000-2012 LOCKON CO.,LTD. All Rights Reserved. |
6 | * |
7 | * http://www.lockon.co.jp/ |
8 | * |
9 | * This program is free software; you can redistribute it and/or |
10 | * modify it under the terms of the GNU General Public License |
11 | * as published by the Free Software Foundation; either version 2 |
12 | * of the License, or (at your option) any later version. |
13 | * |
14 | * This program is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | * GNU General Public License for more details. |
18 | * |
19 | * You should have received a copy of the GNU General Public License |
20 | * along with this program; if not, write to the Free Software |
21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
22 | */ |
23 |
24 | // {{{ requires |
25 | require_once CLASS_EX_REALDIR . 'page_extends/LC_Page_Ex.php' ; |
26 |
27 | /** |
28 | * 商品一覧 のページクラス. |
29 | * |
30 | * @package Page |
31 | * @author LOCKON CO.,LTD. |
32 | * @version $Id: LC_Page_Products_List.php 21988 2012-08-04 17:51:28Z Seasoft $ |
33 | */ |
34 | class LC_Page_News_List extends LC_Page_Ex { |
35 |
36 | // }}} |
37 | // {{{ functions |
38 |
39 | /** |
40 | * Page を初期化する. |
41 | * |
42 | * @return void |
43 | */ |
44 | function init() { |
45 | parent::init(); |
46 | $this ->tpl_subtitle = '新着情報一覧' ; |
47 | } |
48 |
49 | /** |
50 | * Page のプロセス. |
51 | * |
52 | * @return void |
53 | */ |
54 | function process() { |
55 | parent::process(); |
56 | $this ->action(); |
57 | $this ->sendResponse(); |
58 | } |
59 |
60 | /** |
61 | * Page のAction. |
62 | * |
63 | * @return void |
64 | */ |
65 | function action() { |
66 |
67 | $objQuery = SC_Query_Ex::getSingletonInstance(); |
68 | $col = '*' ; |
69 | $from = 'dtb_news' ; |
70 | $where = 'del_flg = 0' ; |
71 | $objQuery ->setOrder( 'news_date desc' ); |
72 | $arrNews = $objQuery ->select( $col , $from , $where ); |
73 | $this ->arrNews = $arrNews ; |
74 |
75 | } |
76 |
77 | /** |
78 | * デストラクタ. |
79 | * |
80 | * @return void |
81 | */ |
82 | function destroy() { |
83 | parent::destroy(); |
84 | } |
85 |
86 | } |
4.data/Smarty/templates/default/news/list.tpl を新規作成
1 | <!--{* |
2 | * This file is part of EC-CUBE |
3 | * |
4 | * Copyright(c) 2000-2012 LOCKON CO.,LTD. All Rights Reserved. |
5 | * |
6 | * http://www.lockon.co.jp/ |
7 | * |
8 | * This program is free software; you can redistribute it and/or |
9 | * modify it under the terms of the GNU General Public License |
10 | * as published by the Free Software Foundation; either version 2 |
11 | * of the License, or (at your option) any later version. |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
19 | * along with this program; if not, write to the Free Software |
20 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 | *}--> |
22 |
23 | < div id = "list_outside" > |
24 | < div id = "undercolumn" class = "undercolumn clearfix" > |
25 |
26 | <!--★タイトル★--> |
27 | < h2 class = "title" > <!--{$tpl_subtitle|h}--> </ h2 > |
28 |
29 | <!--{foreach from=$arrNews item=arrNew name=arrNews}--> |
30 |
31 | <!--{assign var=id value=$arrNew.news_id}--> |
32 | <!--{assign var=arrErr value=$arrNew.arrErr}--> |
33 | <!--▼商品--> |
34 | < div class = "news_list_area clearfix" > |
35 |
36 | < p > <!--{$arrNew.news_date|sfDispDBDate:false|h}--> </ p > |
37 |
38 | <!--★商品名★--> |
39 | < h3 > |
40 | < a href=" <!--{$smarty.const.HTTP_URL}--> news/detail.php?news_id= <!--{$arrNew.news_id|u}--> "> <!--{$arrNew.news_title|h}--> </ a > |
41 | </ h3 > |
42 |
43 | <!--★コメント★--> |
44 | < div class = "listcomment" > |
45 | <!--{$arrNew.news_comment|h|nl2br}--> |
46 | </ div > <!--listcomment end--> |
47 |
48 | </ div > <!--list_area end--> |
49 | <!--▲商品--> |
50 |
51 | <!--{if $smarty.foreach.arrNews.last}--> |
52 |
53 | <!--{/if}--> |
54 |
55 | <!--{foreachelse}--> |
56 | <!--{include file="frontparts/search_zero.tpl"}--> |
57 | <!--{/foreach}--> |
58 |
59 | </ div > |
60 | </ div > <!--list_outside end--> |
5.最後に phpMyAdmin などのDB管理ツールでSQLを流す。
1 | insert into dtb_pagelayout values (10, ( select max (page_id)+1 from dtb_pagelayout where device_type_id = 10), '新着情報一覧ページ' , 'news/list.php' , 'news/list' , 1, 1, 1, 2, NULL , NULL , NULL , now(), now()); |
data/class_extends/… の拡張クラスってどうなんだろうな、と思う今日この頃です。
すばらしいです!1発で動きました!最新の2.13.0の違いはSQLにの最後にmeta_robotsの値を追加するだけでした。