gpt4 book ai didi

php - 如何为横幅添加自定义列而不是右列、左列、顶部列和底部列?

转载 作者:可可西里 更新时间:2023-11-01 08:51:34 25 4
gpt4 key购买 nike

我是 OpenCart 的新手,我想在以下位置添加更多列:

扩展 --> 模块 --> 横幅

例如我想添加:

在位置字段中:

列顶部

栏底

剩下的内容

内容权

列/内容自定义* <---

并希望将此横幅放置在所需页面上的自定义位置。请帮助...!

最佳答案

在管理员中添加职位

首先,您需要打开模块的语言文件; /admin/language/*/module/ 并添加您的新职位。

$_['text_content_middle']       = 'Content Middle';

其次,您需要打开模块的管理模板文件; /admin/view/template/module/ 并在第 50 行左右添加一个新的“if position is set”语句。

<?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>';

第三,您需要打开位于的模块的 Controller 文件; /admin/controller/module/ 并在第 35 行附近的任意位置添加新行。

$this->data['text_content_middle'] = $this->language->get('text_content_middle');

您现在应该能够在模块设置中看到新位置。还要确保模块的布局设置为“主页”。

将位置添加到您的模板

首先,您必须将位置添加到位于的数组中; /catalog/controller/common/home.php 第 20 行左右。

'common/content_middle',

其次,您需要在 /catalog/controller/common/ 中创建相应的 PHP 文件(例如:“content_middle.php”)。添加以下代码,注意第 2、50、79、80 和 82 行)因为需要反射(reflect)您的职位名称:

<?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+) 一个机会!

希望对您有所帮助!

关于php - 如何为横幅添加自定义列而不是右列、左列、顶部列和底部列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13194892/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com