在管理员中添加职位
首先,您需要打开位于的模块语言文件; /admin/language/*/module/ 并添加您的新职位。
$_['text_content_middle'] = 'Content Middle';
其次,您需要打开位于的模块的管理模板文件; /admin/view/template/module/ 并在第 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 } ?>
在同一个文件中,在第 140 行左右将选项添加到 javascript 函数中:
html += ' <option value="content_middle"><?php echo $text_content_middle; ?></option>';
第三,您需要打开位于的模块的控制器文件; /admin/controller/module/ 并在第 35 行附近的任意位置添加新行。
$this->data['text_content_middle'] = $this->language->get('text_content_middle');
您现在应该能够在模块设置中看到新位置。还要确保模块的布局设置为“Home”。
为您的模板添加职位
首先,您必须将位置添加到位于的数组中; /catalog/controller/common/home.php 第 20 行左右。
'common/content_middle',
其次,您需要在/catalog/controller/common/ 中创建相应的 PHP 文件(例如:“content_middle.php”)。添加以下代码,注意第 2、50、79、80 和 82 行)因为需要反映您的职位名称:
<?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();
}
}
?>
第三,在/view/theme/your-theme/template/common/中创建对应的TPL文件(例如:“content_middle.tpl”)。添加以下代码:
<?php foreach ($modules as $module) { ?>
<?php echo $module; ?>
<?php } ?>
现在您可以在主题的 home.tpl 文件中的任何位置调用插入位置,方法是调用
<?php echo $content_middle; ?>
我不鼓励在 OpenCart 中编辑核心文件,给 vQMod (1.5+) 或 OCMod (2+) 一个机会!
希望对您有所帮助!