在opencart中显示子类别中的图像 [英] Showing images in subcategories in opencart
问题描述
最近我第一次安装了Opencart 1.5.6。除了我试图在子类别中显示图像和文本(其中是精炼搜索文本)之外,一切都还不错。
到目前为止,我把它放在 catalog\controller\module \category.php
Recently I installed Opencart 1.5.6 for the first time. Everything in ok except that I trying to show images along with text in sub-categories ( where is Refine Search text ).
So far I've put this in catalog\controller\module\category.php
$children_data[] = array(
'category_id' => $child['category_id'],
'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $product_total . ')' : ''),
'image' => $category['image'],
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}
$this->data['categories'][] = array(
'category_id' => $category['category_id'],
'name' => $category['name'] . ($this->config->get('config_product_count') ? ' (' . $total . ')' : ''),
'image' => $category['image'],
'children' => $children_data,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
新功能'image'=> $类别[图像],
。我也改变了一点 catalog \ view \ theme \ MYTHEME \ template \ product \ category.tpl
这样:
New thing is 'image' => $category['image'],
. I also change a little bit catalog\view\theme\MYTHEME\template\product\category.tpl
like this:
<ul>
<?php foreach ($categories as $category) { ?>
<li>
<img src="../../../../../../image/data/models/<?php echo $category['image']; ?>" width="100"/>
<a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
</li>
<?php } ?>
</ul>
<ul>
<?php $j = $i + ceil(count($categories) / 4); ?>
<?php for (; $i < $j; $i++) { ?>
<?php if (isset($categories[$i])) { ?>
<li>
<img src="../../../../../../image/data/models/<?php echo $categories['image']; ?>" width="100"/>
<a href="<?php echo $categories[$i]['href']; ?>"><?php echo $categories[$i]['name']; ?></a></li>
<?php } ?>
<?php } ?>
</ul>
结果是图像下方图像和文本损坏的框。
The result is box with broken image and text under the image.
我可以从错误中看出它是什么但无法弄清楚如何修复它
< img src =../../../../../../ image / data / models / < b取代;通知及LT; / b计算值:未定义指数:图像中的< b取代; .. \catalog\view\theme\mytheme\template\product\category.tpl< / b>在线路< b取代; 29< / b>中width =100/>
I can see from error what is it but can't figure out how to repair it
<img src="../../../../../../image/data/models/<b>Notice</b>: Undefined index: image in <b>..\catalog\view\theme\mytheme\template\product\category.tpl</b> on line <b>29</b>" width="100"/>
推荐答案
尝试使用默认的OpenCart代码。
Try something like in default OpenCart code.
打开文件目录/视图/主题/<您的主题> / template / template / category.tpl
查找:优化类别代码。
在 之后添加< div class =category-list>
start div
Add after <div class="category-list">
start div
<?php $counter = 0; foreach ($categories as $category) {?>
<div>
<?php if ($category['thumb']) { ?>
<a href="<?php echo $category['href']; ?>"><img src="<?php echo $category['thumb']; ?>" alt="<?php echo $category['name']; ?>" /></a>
<?php } else { ?>
<a href="<?php echo $category['href']; ?>"><img src="image/no_image.jpg" alt="<?php echo $category['name']; ?>" /></a>
<?php } ?>
<a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
</div>
<?php $counter++; } ?>
打开文件目录/ controller / product / category.php
<强>查找强>:
$product_total = $this->model_catalog_product->getTotalProducts($data);
在后添加
$image = $this->model_tool_image->resize($result['image'], $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height'));
在同一个文件中 catalog / controller / product / category.php
查找:
'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url)
替换(而非上线)
'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url), 'thumb' => $image
然后检查它。
这篇关于在opencart中显示子类别中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!