Opencart 2.1.3 |在 category.tpl 上显示一张附加图片和缩略图

Opencart 2.1.3 | Display one additional image along with thumb on category.tpl

除了缩略图,我还想在类别页面上显示每个产品的第一张附加图片,有人知道该怎么做吗?

我知道 Controller 中的 category.php 需要修改以加载附加图像,以便可以在 View category.tpl 上调用它,但我的编码知识还不够好。我已经尝试使用产品中的代码,但我也不完全确定如何在那里调用附加图像。

如有任何帮助,我们将不胜感激!

虽然没有 OpenCart 版本 2.1.3,但您可以通过以下方式在类别页面中显示第一个附加图像。

category.php中找到:

$data['products'][] = array(
    'product_id'  => $result['product_id'],
    'thumb'       => $image,

替换为:

$image_results = $this->model_catalog_product->getProductImages($result['product_id']);

if ($image_results) {
    $image2 = $this->model_tool_image->resize($image_results[0]['image'], $this->config->get($this->config->get('config_theme') . '_image_product_width'), $this->config->get($this->config->get('config_theme') . '_image_product_height'));
} else {
    $image2 = false;
}

$data['products'][] = array(
    'product_id'  => $result['product_id'],
    'thumb'       => $image,
    'thumb2'       => $image2,

然后在category.tpl里,在foreach里面使用:

<?php if($product['thumb2']){ ?><img src="<?php echo $product['thumb2']; ?>"><?php } ?>

我用 OpenCart 2.3.0.2 测试了这个

Source