Opencart 1.5.5.1主页上的图像
我已经在主页上添加模块“类别”,现在我在主页上看到包含产品数量的类别列表,但看不到类别缩略图。Opencart 1.5.5.1主页上的图像
文件:/public_html/catalog/view/theme/MY-THEME/template/module/category.tpl我发现周围的线10:
<a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
,我想sommewhere那里,我也应该添加类似于:category ['thumb']以在类别名称之前显示图像,但是我必须在控制器文件中添加一些内容,我愿意,但是需要帮助。
我的事情我应该在控制器中定义$ category ['thumb']但是如何做到这一点?
你说你需要编辑这个模块的控制器文件是正确的,你需要添加获取该类别图像的模型以及获取任何子类别的图像。所以有两个编辑您需要,首先要控制文件
打开目录/控制器/模块/ category.php &找到这一行:
$this->load->model('catalog/product');
现在,你需要添加模型,以便您可以从数据库中获取的图像数据,加入这一行下面它:
$this->load->model('tool/image');
现在找到这条线,这将是在foreach
循环:
$children = $this->model_catalog_category>getCategories($category['category_id']);
添加以下上述行:
$category_info = $this->model_catalog_category>getCategory($category['category_id']);
if ($category_info['image']) {
$image = $category_info['image'];
} else {
$image = '';
}
您还需要为孩子类别做到这一点,找到这一行,在未来foreach
循环:
$product_total = $this->model_catalog_product->getTotalProducts($data);
添加这个直接以下它:
$child_info = $this->model_catalog_category>getCategory($child['category_id']);
if ($child_info['image']) {
$child_image = $child_info['image'];
} else {
$child_image = '';
}
目前我们现在有两个包含图像路径的变量:$image
和$child_image
,需要将这些变量传递给模板文件,可以通过编辑创建的两个数组来完成。我们将首先执行子数组,因为它几乎直接在您所做的最后一次编辑之下。找到这一行的children_data
数组中:
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
添加逗号行的末尾并粘贴此线正下方:
'image' => $child_image
现在我们添加图片到$category
阵列,发现此线和逗号添加到末尾作为与最后步骤:
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
下一步现在是明显的,其直接添加在它下面的下面的行:
'image' => $image
现在您应该注意,模板文件可以在foreach
循环中访问新变量$ image。我会把剩下的东西留给你,因为你知道你想如何以及在哪里显示图像。
<img src="<?php echo $category['image']; ?>
或者,这可以用于儿童类别:
<img src="<?php echo $child['image']; ?>
的代码,如果它在
foreach
循环或者类别的使用下面将生成的图像