opencart 1.5 how to add module in a header

给你一囗甜甜゛ 提交于 2019-12-21 04:20:58

问题


Please some one tell me how can I position modules like slider or banner in header or how can we define additional regions for the modules.


回答1:


Well, I am working on it.

Firstly, you should add a new position in the admin page. Which means you should change three files and add some lines into each.

For example, if you want to add slideshow into header, you should add a new position in

$this->data['text_header'] = $this->language->get('text_header'); // in admin/controller/slideshow.php

////////////////////////////////////////////////

$_['text_header']         = 'Header'; // in admin/language/slideshow.php

////////////////////////////////////////////////

<?php if ($module['position'] == 'header') { ?> // in admin/view/slideshow.tpl
            <option value="header" selected="selected"><?php echo $text_header; ?></option>
            <?php } else { ?>
            <option value="header"><?php echo $text_header; ?></option>
            <?php } ?>

Then a new position for slideshow has been defined. and you can choose it in the admin page.

After that, you should add those codes in catalog/view/header.tpl

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

Then, in the catalog/controller/header.php, add some codes like content_top.php does: $layout_id = 1;

$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'] == 'header' && $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/header.tpl')) {
    $this->template = $this->config->get('config_template') . '/template/common/header.tpl';
} else {
    $this->template = 'default/template/common/header.tpl';
}

$this->render();

Then all done.

The only problem for this code is the slideshow cannot display as a slideshow but a static picture or pictures.

Wish you could solve it out and reply to me. My question post: Opencart developement: change slideshow's position




回答2:


do what Huawei Chen wrote and then add these to header:

<script type="text/javascript" src="catalog/view/javascript/jquery/nivo-slider/jquery.nivo.slider.pack.js"></script>
<link rel="stylesheet" type="text/css" href="catalog/view/theme/default/stylesheet/slideshow.css" media="screen" />

and slider will be working




回答3:


You can learn from controller/common/column_right.php

Check module position (line 50), you can adapt it to "header":

$module['position'] == 'column_right'

Set the output (line 69), you can adapt it to something like "header_mod" :

$this->data['modules']

You need to modificate module at admin to show additional module position.
There is no "header" module position options at admin page.




回答4:


You can also use an extension that places 2 positions in header and footer. It create the same hooks, like column_left and content_top, etc.

it works with VQmod for opencart 1.5x




回答5:


I think this extension will make your life super simple. http://www.opencart.com/index.php?route=extension/extension/info&token=extension_id=14467

You can add unlimited number of positions to your header, add columns and change there width all through admin

Regards




回答6:


This guide helped me:

http://www.mywork.com.au/blog/create-new-module-layout-position-opencart-1-5/

I was using 1.5.6.1 Opencart version.




回答7:


I read all of your answer. Forget all things. It's very easy to call any module into header section.

Open your catalog/controller/common/header.php file

$this->data['YOUR_MODULE_NAME'] = $this->getChild('module/YOUR_MODULE_NAME');

Now Open .tpl file of header, which is located at catalog/view/theme/YOUR_THEME/template/common/header.tpl

and echo your desire module whenever you want, like as: <?php echo $YOUR_MODULE_NAME;?>

That's it. you are done.




回答8:


You must know that your new position is a new child.

file: catalog/controller/common/header.php

$this->children = array(
'module/language',
'module/currency',
'module/cart'
);

add your new position, like this:

$this->children = array(
'common/content_new',
'module/language',
'module/currency',
'module/cart'
);

now you can echo your new position in your header.tpl



来源:https://stackoverflow.com/questions/7421790/opencart-1-5-how-to-add-module-in-a-header

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!