如何在标题类别菜单中显示子类别图像? [英] How to show subcategory image in header category menù?

查看:100
本文介绍了如何在标题类别菜单中显示子类别图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Opencart版本 2.0.2.0 上,当标题类别下拉菜单打开时,我需要在名称旁边显示子类别图像(缩略图).我尝试自己通过执行代码来获取它,但是没有任何尝试起作用.我需要您的帮助,谢谢.

On Opencart version 2.0.2.0 I need to display the subcategory image (thumb) beside the name when the header category dropdown menu is open. I try to get it by myself acting on code but nothing tried has worked. I need your help thanks in advance.

header.tpl下面的代码中,您看到了我想要子类别图像的位置.它会出现在下拉菜单中.如何自定义header.php文件来实现这一目标?

In the code below header.tpl you see where I want the subcategory image. It wil appear in the dropdown menu. How to customize the header.php file to achieve that?

<?php if ($categories) { ?>
<div class="container">
  <nav id="menu" class="navbar">
    <div class="navbar-header"><span id="category" class="visible-xs"><?php echo $text_category; ?></span>
      <button type="button" class="btn btn-navbar navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse"><i class="fa fa-bars"></i></button>
    </div>
    <div class="collapse navbar-collapse navbar-ex1-collapse">
      <ul class="nav navbar-nav">
        <?php foreach ($categories as $category) { ?>
        <?php if ($category['children']) { ?>
        <li class="dropdown"><a href="<?php echo $category['href']; ?>" class="dropdown-toggle" data-toggle="dropdown"><?php echo $category['name']; ?></a>
          <div class="dropdown-menu">
            <div class="dropdown-inner">
              <?php foreach (array_chunk($category['children'], ceil(count($category['children']) / $category['column'])) as $children) { ?>
              <ul class="list-unstyled">
                <?php foreach ($children as $child) { ?>
                <li><a href="<?php echo $child['href']; ?>"><?php echo $child['name']; ?></a></li>

                 SUBCATEGORY IMAGE HERE

                <?php } ?>
              </ul>
              <?php } ?>
            </div>
            <a href="<?php echo $category['href']; ?>" class="see-all"><?php echo $text_all; ?> <?php echo $category['name']; ?></a> </div>
        </li>
        <?php } else { ?>
        <li><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a></li>
        <?php } ?>
        <?php } ?>
      </ul>
    </div>
  </nav>
</div>
<?php } ?>

推荐答案

在您的header.php(目录>控制器>通用)中,这些数组负责显示类别数据(显示在标题

In your header.php (catalog > controller > common) these is this array which is responsible for the category child data, which displays in header

$children_data;

因此,您只需要在此数组中添加thumb/图像即可,好处是它已包含在已获取的数据中,因此只需将图像添加到此数组中即可.为此,您必须先添加调整大小(好习惯)的图片,只需加载图片模型

so you just need to add thumb/ image in this array and good thing is that it is in already fetched data so just add image to this array. For this you have to add resize (good habit) image first, just load image model

    $this->load->model('tool/image');

在此行之后(无限制,在任何位置添加;))

after this line (no restriction, add anywhere you want ;) )

    $this->load->model('catalog/product');

现在将图像索引添加到类别子数组中

now add image index in your category child array

    $children_data[] = array(

我这样添加

    $children_data[] = array(
    'image'  => $child['image'] ? $this->model_tool_image->resize($child['image'], 20, 20) : false,

它将检查类别中是否有图像,如果您想始终显示图像,则可以使用它

it will check if category has image or not, if you want to display image always then you can use this

    'image'  => $child['image'] ? $this->model_tool_image->resize($child['image'], 20, 20) : $this->model_tool_image->resize('your-default-image.jpg', 20, 20),

现在您的控制器工作已经完成.现在该查看模板中的这些更改.将此代码添加到header.tpl(目录>视图>主题>您的主题(默认设置)>模板>),然后根据需要在问题中添加此代码

now your controller work is done. It's time to view these changes in template. Add this code to header.tpl (catalog > view > theme > your-theme (mine default) > template >) and add this code like you want in your question

      <?php if($child['image']){ ?>
            <img src="<?php echo $child['image']; ?>" />
      <?php } ?>

它将像这样显示

不是很甜:)

注意-请使用vqmod/ocmod添加此更改.直接更改核心文件是个坏主意.

Note - Please add this changes with vqmod/ ocmod . Direct changes in core files is bad idea.

这篇关于如何在标题类别菜单中显示子类别图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆