Opencart 2.1.3 |在category.tpl上显示一个附加图像和拇指

问题描述 投票:0回答:1

除了拇指图像我想在类别页面上显示每个产品的第一个附加图像,有谁知道如何做到这一点?

我知道Controller中的category.php需要修改才能加载额外的图像,以便可以调用View category.tpl但我的编码知识不够好。我已经尝试使用产品中的代码,但我不完全确定如何在其中调用其他图像。

任何帮助,将不胜感激!

php opencart opencart2.x
1个回答
0
投票

虽然没有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

© www.soinside.com 2019 - 2024. All rights reserved.