zen-cart開發教程 – 開發Sidebox外掛程式

來源:互聯網
上載者:User

首先需要搞清楚什麼是Sidebox,Sidebox是一個顯示在左側或者右側的內容地區,當然你也可以將Sidebox的單欄狀態開啟,使其顯示在網頁的任何位置。你可以通過進入背景Tools/Layout Boxes Controller來進行Sidebox的設定。注意的是如果開啟了單欄Sidebox的話,你必須通過一句代碼手動將其顯示到模板中去,否則你是看不到任何效果的。zen-cart中內建了很多Sidebox, 例如顯示產品分類的Sidebox, 顯示最新產品的Sidebox, 選擇語言的Sidebox等等。

  1. Sidebox相關的檔案和目錄

    輸出左側sidebox的檔案:/includes/modules/column_left.php

    輸出右側側sidebox的檔案:/includes/modules/column_right.php

    輸出單欄sidebox的檔案:/includes/modules/column_single.php

     

    儲存sidebox的位置:/includes/modules/sideboxes

    Sidebox模版位置:/includes/templates/template_default/sideboxes

     

    預設左側sidebox模版/includes/templates/template_default/common/tpl_box_default_left.php

    預設右側sidebox模版:/includes/templates/template_default/common/tpl_box_default_right.php

    預設單欄sidebox模版:/includes/templates/template_default/common/ tpl_box_default_single.php

  2. 執行個體: hello_sidebox的開發
    下面我們來開發一個簡單的sidebox,以說明開發一個Sidebox的基本步驟,該sidebox只顯示一段文字,並不實現任何功能, 我們將這個 sizebox命名為 hello_sidebox。
    1). 設定語言和要在sidebox中顯示的內容
       在目錄” /includes/languages/english/extra_definitions”建立一個PHP檔案,命名為” hello_sidebox.php”, 並設定英語環境下sidebox的Title和要顯示的內容。該檔案中定義了兩個常量BOX_HEADING_HELLOW_SIDEBOX(sidebox的標題), 'BOX_HEADING_HELLOW_SIDEBOX_CONTENT(顯示的內容),代碼如下 define(BOX_HEADING_HELLOW_SIDEBOX, "Hello sidebox");
    define(BOX_HEADING_HELLOW_SIDEBOX_CONTENT, "This is a sidebox demo");

    2).   建立sidebox檔案
       在目錄”/includes/modules/sideboxes”下面建立一個 檔案, 命名為” hello_sidebox.php”, 並輸入以下代碼, 其中第一行載入了hello_sidebox的模板檔案, 第二行設定了sidebox的標題, 第三行代碼載入了用來輸出sidebox的模板檔案.

     require($template->get_template_dir('tpl_wp_cats.php',DIR_WS_TEMPLATE, $current_page_base,'sideboxes'). '/tpl_hello_sidebox.php');
      $title =  BOX_HEADING_HELLOW_SIDEBOX;  
     require($template->get_template_dir($column_box_default, DIR_WS_TEMPLATE, $current_page_base,'common') . '/' . $column_box_default);

    3).   建立sidebox模版檔案
         sidebox模板檔案實際上並不會輸出任何內容到網頁上面, 這裡只是構造了要在Sidebox內部顯示的內容(變數$content). 這裡, 我們的內容僅僅是將常量BOX_HEADING_HELLOW_SIDEBOX_CONTENT的值賦給$content,代碼如下.

    $content = "";
    $content .= BOX_HEADING_HELLOW_SIDEBOX_CONTENT;


    4).   安裝sidebox

    進入管理後台>>Tools>>Layout Boxes Controller, 就可以看到我們剛才開發的hello_sidebox外掛程式了, 選中hello_sidebox, 點擊編輯按鈕, 將Left/Right Column Status設定為on, 再點擊Update按鈕, 這樣安裝過程就完成了. 現在再重新整理一下首頁, 是不是就能看到我們的hello_sidebox盒子了呢?

    5).   發布sidebox

    將剛才的檔案按照原始的目錄結構進行打包, 如所示, 就算髮布成功了. 這樣就可以把我們開發好的外掛程式共用給別人使用了.

     

    怎麼樣,很簡單吧。該樣本雖然很簡單,卻也涵蓋了開發Sidebox的基本步驟,有了這些基礎,你可以開發出更多複雜的應用。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.