问题
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.
回答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
回答2:
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
来源:https://stackoverflow.com/questions/7966066/opencart-developement-change-slideshows-position