请有人告诉我如何在标题中定位滑块或横幅等模块,或者我们如何为模块定义其他区域。
8 回答
嗯,我正在努力。
首先,您应该在管理页面中添加一个新位置。这意味着您应该更改三个文件并在每个文件中添加一些行。
例如,如果您想在页眉中添加幻灯片,您应该在页眉中添加一个新位置
$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 } ?>
然后定义了幻灯片的新位置。您可以在管理页面中选择它。
之后,您应该将这些代码添加到 catalog/view/header.tpl
<?php foreach ($modules as $module) { ?>
<?php echo $module; ?>
<?php } ?>
然后,在目录/控制器/header.php 中,添加一些类似 content_top.php 的代码: $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();
然后全部完成。
此代码的唯一问题是幻灯片不能显示为幻灯片,而是静态图片或图片。
希望你能解决它并回复我。我的问题帖子: Opencart 开发:更改幻灯片的位置
做华为陈写的,然后将这些添加到标题中:
<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" />
和滑块将工作
可以参考controller/common/column_right.php
检查模块位置(第 50 行),您可以将其调整为“标题”:
$module['position'] == 'column_right'
设置输出(第 69 行),您可以将其调整为类似 "header_mod" 的内容:
$this->data['modules']
您需要在管理员处修改模块以显示其他模块位置。
管理页面没有“标题”模块位置选项。
您还可以使用在页眉和页脚中放置 2 个位置的扩展。它创建相同的钩子,例如column_left
andcontent_top
等。
我认为这个扩展会让你的生活变得超级简单。http://www.opencart.com/index.php?route=extension/extension/info&token=extension_id=14467
您可以在标题中添加无限数量的位置,添加列并通过管理员更改宽度
问候
本指南帮助了我:
http://www.mywork.com.au/blog/create-new-module-layout-position-opencart-1-5/
我使用的是 1.5.6.1 Opencart 版本。
我读了你所有的答案。忘记一切。将任何模块调用到标题部分非常容易。
打开你的catalog/controller/common/header.php
文件
$this->data['YOUR_MODULE_NAME'] = $this->getChild('module/YOUR_MODULE_NAME');
现在打开.tpl
头文件,位于
catalog/view/theme/YOUR_THEME/template/common/header.tpl
并在您需要时回显您的愿望模块,例如:
<?php echo $YOUR_MODULE_NAME;?>
就是这样。你完成了。
你必须知道你的新职位是一个新的孩子。
file: catalog/controller/common/header.php
$this->children = array(
'module/language',
'module/currency',
'module/cart'
);
添加您的新职位,如下所示:
$this->children = array(
'common/content_new',
'module/language',
'module/currency',
'module/cart'
);
现在您可以在 header.tpl 中回显您的新位置