Opencart developement: change slideshow's position
Asked Answered
C

2

1

I am working with opencart. I want to change slideshow from "content-top" to "header". It means, I wanna move the slideshow above the top menu, and it will also displays in every page instead of in home page only.

I've done following steps: 1st: add a position named "header" in admin three "slideshow.php" files (controller, language, and view folders). 2nd: I modified header.php:(add those codes after the "//menu" code block in controller folder)

    $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();

3rd: add codes in header.tpl file: still, before the "//menu" code block. (in view folder)

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

Now, the problem is: the javascript codes in banner.tpl will not run anymore. Luckily however, the javascript codes in slideshow.tpl still run.

So, currently, the website displays the banner in header position, before the menu in Home page, but the slideshow effect doesn't. If you set two photos, both of them will display in the front page. They will not change with each other any more.

Cyano answered 1/11, 2011 at 12:0 Comment(0)
S
1

first of all u can't just go ahead and copy past

you should understand what you will do

the slide show is slidshow.tpl and slideshow.php to include the javascript you need the following line of code in your /controller/commun/header.php

$this->document->addScript('catalog/view/javascript/jquery/nivo-slider/jquery.nivo.slider.pack.js');

so the javascript can work

Smith answered 1/11, 2011 at 13:34 Comment(4)
Give me more info's about what you want to achieve i will help you ;Smith
Thank you mate, and also I discovered, I need to add slideshow.css file into it also. Otherwise the slideshow will run in a disordered layout.Cyano
Why adding a JS and CSS through $this->document->addXXX() works in header.php controller while adding a <script src="..."></script> in header.tpl does not???Experientialism
Don't know, if you check the header.tpl you will find that addXXX() will do exactly the same , it outputs links to scripts and CSS it is just cleaner waySmith
C
0

you can use a simple module for that that adds these positions and keeps the javascripts working proparly.

http://www.opencart.com/index.php?route=extension/extension/info&token=extension_id=14467

Also you can add unlimited number of positions, add columns and change there width and it works with all themes and modules.

Regards

Caa answered 20/11, 2013 at 18:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.