dongshenling6585 2012-11-02 12:04
浏览 47
已采纳

如何为横幅而不是向右,向左,向上和向下的列添加自定义列?

I am new in OpenCart and I want to add more columns in:

Extensions --> Modules --> Banner

For Example I want to add:

In Position field:

Column Top

Column Bottom

Content Left

Content Right

Column/Content Custom * <---

And want to place this banner on the custom position on the desired page. Please help...!

  • 写回答

1条回答 默认 最新

  • dongzhang6021 2015-01-14 04:10
    关注

    Adding positions in admin

    First, you need to open the module's language file located in; /admin/language/*/module/ and add your new position.

    $_['text_content_middle']       = 'Content Middle';
    

    Second, you need to open your module's admin template file located in; /admin/view/template/module/ and add a new "if position is set" statement at around line 50.

    <?php if ($module['position'] == 'content_middle') { ?>
    <option value="content_middle" selected="selected"><?php echo $text_content_middle; ?></option>
    <?php } else { ?>
    <option value="content_middle"><?php echo $text_content_middle; ?></option>
     <?php } ?>
    

    and in the same file add the option to the javascript function at around line 140:

    html += '      <option value="content_middle"><?php echo $text_content_middle; ?></option>';
    

    Third, you need to open the module's controller file located in; /admin/controller/module/ and add a new line anywhere around line 35.

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

    You should now be able to see the new position in your modules settings. Also make sure the module's layout is set to "Home."

    Adding positions to your templates

    First, you must add the position to the array located in; /catalog/controller/common/home.php around line 20.

    'common/content_middle',
    

    Second, you'll need to create the corresponding PHP file in /catalog/controller/common/ (for example: "content_middle.php"). Add the following code, pay attention to lines 2, 50, 79, 80, and 82) as will need to reflect your position's name:

    <?php
    class ControllerCommonHomeOne extends Controller {
        public function index() {
            $this->load->model('design/layout');
            $this->load->model('catalog/category');
            $this->load->model('catalog/product');
            $this->load->model('catalog/information');
    
            if (isset($this->request->get['route'])) {
                $route = $this->request->get['route'];
            } else {
                $route = 'common/home';
            }
    
            $layout_id = 0;
    
            if (substr($route, 0, 16) == 'product/category' && isset($this->request->get['path'])) {
                $path = explode('_', (string)$this->request->get['path']);
    
                $layout_id = $this->model_catalog_category->getCategoryLayoutId(end($path));
            }
    
            if (substr($route, 0, 15) == 'product/product' && isset($this->request->get['product_id'])) {
                $layout_id = $this->model_catalog_product->getProductLayoutId($this->request->get['product_id']);
            }
    
            if (substr($route, 0, 23) == 'information/information' && isset($this->request->get['information_id'])) {
                $layout_id = $this->model_catalog_information->getInformationLayoutId($this->request->get['information_id']);
            }
    
            if (!$layout_id) {
                $layout_id = $this->model_design_layout->getLayout($route);
            }
    
            if (!$layout_id) {
                $layout_id = $this->config->get('config_layout_id');
            }
    
            $module_data = array();
    
            $this->load->model('setting/extension');
    
            $extensions = $this->model_setting_extension->getExtensions('module');
    
            foreach ($extensions as $extension) {
                $modules = $this->config->get($extension['code'] . '_module');
    
                if ($modules) {
                    foreach ($modules as $module) {
                        if ($module['layout_id'] == $layout_id && $module['position'] == 'home_one' && $module['status']) {
                            $module_data[] = array(
                                'code'       => $extension['code'],
                                'setting'    => $module,
                                'sort_order' => $module['sort_order']
                            );
                        }
                    }
                }
            }
    
            $sort_order = array();
    
            foreach ($module_data as $key => $value) {
                $sort_order[$key] = $value['sort_order'];
            }
    
            array_multisort($sort_order, SORT_ASC, $module_data);
    
            $this->data['modules'] = array();
    
            foreach ($module_data as $module) {
                $module = $this->getChild('module/' . $module['code'], $module['setting']);
    
                if ($module) {
                    $this->data['modules'][] = $module;
                }
            }
    
            if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/home_one.tpl')) {
                $this->template = $this->config->get('config_template') . '/template/common/home_one.tpl';
            } else {
                $this->template = 'default/template/common/home_one.tpl';
            }
    
            $this->render();
        }
    }
    ?>
    

    Third, create the corresponding TPL file in /view/theme/your-theme/template/common/ (for example: "content_middle.tpl"). Add the following code:

    <?php foreach ($modules as $module) { ?>
    <?php echo $module; ?>
    <?php } ?>
    

    Now you can call your insert your position anywhere in your theme's home.tpl file by calling

    <?php echo $content_middle; ?>
    

    I'm not encourage to edit the core files in OpenCart, give vQMod (1.5+) or OCMod (2+) a chance!

    Hope this help!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 很想要一个很好的答案或提示
  • ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr
  • ¥15 怀疑手机被监控,请问怎么解决和防止
  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL