将类别图像作为菜单中的缩略图,OpenCart 2.0.x
Making category image as thumb in menu, OpenCart 2.0.x
我很难做到这一点。我要做的是我希望我的菜单中的类别图像作为 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 中的另一个框架完成过此操作。但这对我也没有太大帮助呵呵。如果你愿意,我可以将其他代码粘贴到。
因为$category['thumb']
模板文件中只包含图片源所以
替换<?php $category['thumb']?>
和<img src="<?php echo $category['thumb']?>" alt="<?php echo $child['name']; ?>"/>
此外,在控制器中,您正在设置父类别的缩略图,并在子类别的模板打印中设置它,因此它会一次又一次地打印相同的父图像。
no_image.jpg
在最新版本中被替换为no_image.png
。
我遇到了同样的问题并在 Opencart 2.1.0.1 上运行
这是 catalog/controller/common/header.php 文件:
(line 113)
// 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
);
$this->load->model('tool/image');
$image = empty($child['image']) ? 'no_image.png' : $child['image'];
$thumb = $this->model_tool_image->resize($image, 100, 100);
$children_data[] = array(
'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
'thumb' => $thumb,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}
这是我的 catalog/view/theme/default/template/common/header.tpl 文件:
(line 108)
<li><a href="<?php echo $child['href']; ?>"><img src="<?php echo $child['thumb']?>" alt="<?php echo $child['name']; ?>"/><br /><?php echo $child['name']; ?></a></li>
希望对您有所帮助。
我很难做到这一点。我要做的是我希望我的菜单中的类别图像作为 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 中的另一个框架完成过此操作。但这对我也没有太大帮助呵呵。如果你愿意,我可以将其他代码粘贴到。
因为$category['thumb']
模板文件中只包含图片源所以
替换<?php $category['thumb']?>
和<img src="<?php echo $category['thumb']?>" alt="<?php echo $child['name']; ?>"/>
此外,在控制器中,您正在设置父类别的缩略图,并在子类别的模板打印中设置它,因此它会一次又一次地打印相同的父图像。
no_image.jpg
在最新版本中被替换为no_image.png
。
我遇到了同样的问题并在 Opencart 2.1.0.1 上运行 这是 catalog/controller/common/header.php 文件:
(line 113)
// 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
);
$this->load->model('tool/image');
$image = empty($child['image']) ? 'no_image.png' : $child['image'];
$thumb = $this->model_tool_image->resize($image, 100, 100);
$children_data[] = array(
'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
'thumb' => $thumb,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}
这是我的 catalog/view/theme/default/template/common/header.tpl 文件:
(line 108)
<li><a href="<?php echo $child['href']; ?>"><img src="<?php echo $child['thumb']?>" alt="<?php echo $child['name']; ?>"/><br /><?php echo $child['name']; ?></a></li>
希望对您有所帮助。