Labo

[EC-CUBE 2.12.2] 新着情報一覧ページを作成

2012年11月24日 / 投稿者名:fukap


前回は、新着情報詳細ページ作成をやってみましたが、今回はその続編ということで、
新着情報一覧ページ作成にチャレンジしたいと思います。
PC用ページとして作成してみました。

 

1.html/news/list.php を新規作成

<?php
/*
 * This file is part of EC-CUBE
 *
 * Copyright(c) 2000-2012 LOCKON CO.,LTD. All Rights Reserved.
 *
 * http://www.lockon.co.jp/
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

// {{{ requires
require_once '../require.php';
require_once CLASS_EX_REALDIR . 'page_extends/news/LC_Page_News_List_Ex.php';

// }}}
// {{{ generate page

$objPage = new LC_Page_News_List_Ex();
register_shutdown_function(array($objPage, 'destroy'));
$objPage->init();
$objPage->process();

2.data/class_extends/page_extends/news/LC_Page_News_List_Ex.php を新規作成

<?php
/*
 * This file is part of EC-CUBE
 *
 * Copyright(c) 2000-2012 LOCKON CO.,LTD. All Rights Reserved.
 *
 * http://www.lockon.co.jp/
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

// {{{ requires
require_once CLASS_REALDIR . 'pages/news/LC_Page_News_List.php';

/**
 e LC_Page_News_List のページクラス(拡張).
 *
 * LC_Page_News_List をカスタマイズする場合はこのクラスを編集する.
 *
 * @package Page
 * @author LOCKON CO.,LTD.
 * @version $Id: LC_Page_Products_List_Ex.php 21867 2012-05-30 07:37:01Z nakanishi $
 */
class LC_Page_News_List_Ex extends LC_Page_News_List {

    // }}}
    // {{{ nunctions

    /**
     * Page を初期化する.
     *
     * @return void
     */
    function init() {
        parent::init();
    }

    /**
     * Page のプロセス.
     *
     * @return void
     */
    function process() {
        parent::process();
    }

    /**
     * デストラクタ.
     *
     * @return void
     */
    function destroy() {
        parent::destroy();
    }
}

3.data/class/pages/news/LC_Page_News_List.php を新規作成

<?php
/*
 * This file is part of EC-CUBE
 *
 * Copyright(c) 2000-2012 LOCKON CO.,LTD. All Rights Reserved.
 *
 * http://www.lockon.co.jp/
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

// {{{ requires
require_once CLASS_EX_REALDIR . 'page_extends/LC_Page_Ex.php';

/**
 * 商品一覧 のページクラス.
 *
 * @package Page
 * @author LOCKON CO.,LTD.
 * @version $Id: LC_Page_Products_List.php 21988 2012-08-04 17:51:28Z Seasoft $
 */
class LC_Page_News_List extends LC_Page_Ex {

    // }}}
    // {{{ functions

    /**
     * Page を初期化する.
     *
     * @return void
     */
    function init() {
        parent::init();
		$this->tpl_subtitle = '新着情報一覧';
    }

    /**
     * Page のプロセス.
     *
     * @return void
     */
    function process() {
        parent::process();
        $this->action();
        $this->sendResponse();
    }

    /**
     * Page のAction.
     *
     * @return void
     */
    function action() {

		$objQuery = SC_Query_Ex::getSingletonInstance();
		$col = '*';
		$from = 'dtb_news';
		$where = 'del_flg = 0';
		$objQuery->setOrder('news_date desc');
		$arrNews = $objQuery->select($col, $from, $where);
		$this->arrNews = $arrNews;

    }

    /**
     * デストラクタ.
     *
     * @return void
     */
    function destroy() {
        parent::destroy();
    }

}

4.data/Smarty/templates/default/news/list.tpl を新規作成

<!--{*
 * This file is part of EC-CUBE
 *
 * Copyright(c) 2000-2012 LOCKON CO.,LTD. All Rights Reserved.
 *
 * http://www.lockon.co.jp/
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *}-->

<div id="list_outside">
<div id="undercolumn" class="undercolumn clearfix">

    <!--★タイトル★-->
    <h2 class="title"><!--{$tpl_subtitle|h}--></h2>

    <!--{foreach from=$arrNews item=arrNew name=arrNews}-->

        <!--{assign var=id value=$arrNew.news_id}-->
        <!--{assign var=arrErr value=$arrNew.arrErr}-->
        <!--▼商品-->
        <div class="news_list_area clearfix">

			<p><!--{$arrNew.news_date|sfDispDBDate:false|h}--></p>

            <!--★商品名★-->
            <h3>
                <a href="<!--{$smarty.const.HTTP_URL}-->news/detail.php?news_id=<!--{$arrNew.news_id|u}-->"><!--{$arrNew.news_title|h}--></a>
            </h3>

            <!--★コメント★-->
            <div class="listcomment">
            <!--{$arrNew.news_comment|h|nl2br}-->
            </div><!--listcomment end-->

        </div><!--list_area end-->
        <!--▲商品-->

        <!--{if $smarty.foreach.arrNews.last}-->

        <!--{/if}-->

    <!--{foreachelse}-->
        <!--{include file="frontparts/search_zero.tpl"}-->
    <!--{/foreach}-->

</div>
</div><!--list_outside end-->

5.最後に phpMyAdmin などのDB管理ツールでSQLを流す。

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/… の拡張クラスってどうなんだろうな、と思う今日この頃です。

[EC-CUBE 2.12.2] 新着情報一覧ページを作成 への1件のコメント

  1. yt より:

    すばらしいです!1発で動きました!最新の2.13.0の違いはSQLにの最後にmeta_robotsの値を追加するだけでした。

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

* Copy This Password *

* Type Or Paste Password Here *

*

コメント欄にコードを挿入したい場合は、[php][/php] を使ってください。