【发布时间】:2016-02-25 07:35:42
【问题描述】:
我很难做到这一点。我要做的是我希望菜单中的类别图像作为 Opencart 2.0.x 中的拇指。
我已将 'thumb' => $thumb, 放入 catalog/controller/common/header.tpl
像这样:
// Menu
$this->load->model('catalog/category');
$this->load->model('catalog/product');
$data['categories'] = array();
$categories = $this->model_catalog_category->getCategories(0);
foreach ($categories as $category) {
if ($category['top']) {
// Level 2
$children_data = array();
$children = $this->model_catalog_category->getCategories($category['category_id']);
foreach ($children as $child) {
$filter_data = array(
'filter_category_id' => $child['category_id'],
'filter_sub_category' => true
);
$children_data[] = array(
'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}
// Level 1
$this->load->model('tool/image');
$image = empty($category['image']) ? 'no_image.jpg' : $category['image'];
$thumb = $this->model_tool_image->resize($image, 100, 100);
$data['categories'][] = array(
'name' => $category['name'],
'children' => $children_data,
'thumb' => $thumb,
'column' => $category['column'] ? $category['column'] : 1,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}
}
我还把 $category['thumb'] 放在 catalog/view/theme/default/template/common/header.tpl
像这样:
<?php if ($categories) { ?>
<nav id="navigation">
<div class="boxed bg-navigation">
<div class="container">
<ul data-breakpoint="800" class="flexnav with-js lg-screen clearfix">
<?php foreach ($categories as $category) { ?>
<?php if ($category['children']) { ?>
<li><a href="<?php echo $category['href']; ?>" ><?php echo $category['name']; ?></a>
<ul class="list-unstyled ul-col-<?php echo $category['column']; ?>">
<?php foreach (array_chunk($category['children'], ceil(count($category['children']) / $category['column'])) as $children) { ?>
<?php if ($category['column'] == 1) { ?>
<?php foreach ($children as $child) { ?>
<li><a href="<?php echo $child['href']; ?>"><?php echo $child['name']; ?></a></li>
<?php } ?>
<?php } else { ?>
<li class="li-inline">
<div>
<?php foreach ($children as $child) { ?>
<?php $category['thumb']?>
<a href="<?php echo $child['href']; ?>"><?php echo $child['name']; ?></a>
<?php } ?>
</div>
</li>
<?php } ?>
<?php } ?>
</ul>
</li>
<?php } else { ?>
<li><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a></li>
<?php } ?>
<?php } ?>
</ul>
</div>
</div>
</nav>
<?php } ?>
我在这里做错了什么?我在 Stack Overflow Solution
上找到了这个解决方案但我似乎无法正确解决此问题,这可能是一件我看不到的简单事情。我之前使用 OpenCart 1.5.6.4 中的另一个框架完成了此操作。但这也没有帮助我很多呵呵。如果你愿意,我可以将其他代码粘贴到。
【问题讨论】:
标签: image opencart2.x