用英文"Creating a custom page in opencart"搜尋這個問題,

會發現很多人都會有這樣的問題,

想要在底部(footer)新增一個連結做說明,

如下圖 "客製化網頁"

opencart 客製化 底部 footer  

卻不知如何做起。

我在opencart的官方討論區找到有人回答了這個問題,

非常詳細,還有Q&A,

有興趣的朋友可以去看,

原文網址如下:

http://forum.opencart.com/viewtopic.php?t=59542

 

我用中文詳列了步驟:

假設我們要新增一個叫"客製化網頁"的連結。

 

1. 在 /catalog/controller/information 資料夾底下新增一個 custom.php的檔案

檔案內容請貼上

<?php
class ControllerInformationCustom extends Controller {
   private $error = array();
      
     public function index() {
      $this->language->load('information/custom'); //Optional. This calls for your language file

       $this->document->setTitle($this->language->get('heading_title')); //Optional. Set the title of your web page.

         $this->data['breadcrumbs'] = array();

         $this->data['breadcrumbs'][] = array(
           'text'      => $this->language->get('text_home'),
         'href'      => $this->url->link('common/home'),           
           'separator' => false
         );

         $this->data['breadcrumbs'][] = array(
           'text'      => $this->language->get('heading_title'),
         'href'      => $this->url->link('information/custom'),
           'separator' => $this->language->get('text_separator')
         );   
         
       $this->data['heading_title'] = $this->language->get('heading_title'); //Get "heading title" from language file.

      if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/information/custom.tpl')) { //if file exists in your current template folder
         $this->template = $this->config->get('config_template') . '/template/information/custom.tpl'; //get it
      } else {
         $this->template = 'default/template/information/custom.tpl'; //or get the file from the default folder
      }
      
      $this->children = array( //Required. The children files for the page.
         'common/column_left',
         'common/column_right',
         'common/content_top',
         'common/content_bottom',
         'common/footer',
         'common/header'
      );
            
      $this->response->setOutput($this->render());      
     }
}
?>

 

2.  在 /catalog/controller/common/footer.php 加上兩行程式碼

找到

$this->data['text_newsletter'] = $this->language->get('text_newsletter');

在這行後面貼上

$this->data['text_custom'] = $this->language->get('text_custom');

 

找到

$this->data['newsletter'] = $this->url->link('account/newsletter', '', 'SSL');

在這行後面貼上

$this->data['custom'] = $this->url->link('information/custom');

 

 

3. 在 /catalog/view/theme/default/template/information/ 新增一個 custom.tpl的檔案

如果你有使用template,

那麼路徑中的default就要改成你用的模組的名字

檔案內容請貼上

<?php echo $header; ?><?php echo $column_left; ?><?php echo $column_right; ?>
<div id="content"><?php echo $content_top; ?>
  <div class="breadcrumb">
    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
    <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
    <?php } ?>
  </div>
  <h1><?php echo $heading_title; ?></h1>
 
  你要顯示的網頁內容
 
   <?php echo $content_bottom; ?></div>
<?php echo $footer; ?>

 

4. 在 /catalog/view/theme/default/template/common/footer.tpl 加上一行程式碼

如果你有使用template,

那麼路徑中的default就要改成你用的模組的名字

 

假設你要在網站地圖下面加上連結,

如圖所示,

opencart 客製化 底部 footer

 

那就在檔案裡面找到網站地圖(sitemap)這行

<li><a href="<?php echo $sitemap; ?>"><?php echo $text_sitemap; ?></a></li>

在這行之後加上

<li><a href="<?php echo $custom; ?>"><?php echo $text_custom; ?></a></li>

 

 

 

 

5. 在 /catalog/language/english/information 新增一個 custom.php的檔案

如果你有用中文模組,

那麼就要在/catalog/language/zH-TW/information 資料夾底下新增

檔案內容請貼上

<?php
// Heading
$_['heading_title']  = '你要顯示的網頁標題';
?>

 

 

 

6. 在 /catalog/language/english/common/footer.php 加上一行程式碼

 

如果你有用中文模組,

 

那麼就要在/catalog/language/zH-TW/common/footer.php 修改

 

找到

$_['text_newsletter']   = 'Newsletter';

在這行後面貼上

$_['text_custom']       = '客製化網頁';

 

一切就大功告成啦 !!

 

 

 

arrow
arrow
    文章標籤
    opencart 客製 底部 footer
    全站熱搜
    創作者介紹
    創作者 ChengTaHsieh 的頭像
    ChengTaHsieh

    Hunter的部落格

    ChengTaHsieh 發表在 痞客邦 留言(0) 人氣()