Php 如何在Opencart子类别中显示图像而不是名称(文本)?

Php 如何在Opencart子类别中显示图像而不是名称(文本)?,php,smarty,opencart,categories,Php,Smarty,Opencart,Categories,因此Opencart上的普通子类别如下所示,例如: 类别:苹果 子类别:iPhone3、iPhone4、iPhone5 现在,这些子类别都是文本,但我想在子类别页面(www.site.com/Apple)上显示它们的图像 对于category.php文件,它位于catelog/controller/module/category.php中 我添加了以下代码: $this->load->model('tool/image'); $image = empty($category['ima

因此Opencart上的普通子类别如下所示,例如: 类别:苹果 子类别:iPhone3、iPhone4、iPhone5

现在,这些子类别都是文本,但我想在子类别页面(www.site.com/Apple)上显示它们的图像

对于category.php文件,它位于catelog/controller/module/category.php中 我添加了以下代码:

$this->load->model('tool/image');
$image = empty($category['image']) ? 'no_image.jpg' : $category['image'];
$thumb = $this->model_tool_image->resize($image, 100, 100);
然后是子类别数组,通常如下所示:

$children_data[] = array(               
 'category_id' => $child['category_id'],                    
 'name'        => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $product_total . ')' : ''),                         
 'href'        => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
我在中添加了以下对象:

'thumb'       => $thumb,    
最后,在我的视图文件category.tpl中,位于:view/theme/myteme/template/product/category.tpl,有一行:

<li><a href="<?php echo $categories[$i]['href']; ?>"><?php echo $categories[$i]['name']; ?></a></li>
  • 我将['name']改为['thumb'](在php引号周围添加了html标记)。 但在这一切之后,我仍然被这个错误所困扰:

    PHP注意:未定义索引:第36行/home/web/catalog/view/theme/theme/template/product/category.tpl中的图像

    我已经被这个问题困扰了好几个小时,非常感谢您的帮助!

    使用下面的代码

    查找代码(在category.php中)

    替换代码

    $image = $this->model_tool_image->resize($result['image'], $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height'));
                $this->data['categories'][] = array(
                    'name'  => $result['name'] . ($this->config->get('config_product_count') ? ' (' . $product_total . ')' : ''),
                    'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url), 'thumb' => $image
                );
    
    &而且

    添加代码(在category.tpl中)

    
    

    &然后检查它。

    您的代码似乎正常,但错误告诉您有一个变量“$image”这是没有指定的,从上面的代码中应该没有这样的变量,所以这有点尴尬,请确认没有vqmod脚本弄乱事情。我想我是在错误的文件夹中工作的,我刚刚发现。因为类别的控制器中的内容是针对真实类别的。但我不想为该类别显示图像类别,仅用于子类别。我认为这些是在产品文件夹中,而不是在模块文件夹中。yeap显示为页面的类别在产品文件夹的category.tpl中有所有需要的数据,模块文件夹中的category.tpl仅用于您需要首先作为扩展激活的模块,依此类推。在Opencart上,如果您有一个类别叫做苹果。现在在这个类别中,子类别是:iPhone 3,iPhone 4。我只想更改子类别的文本,而不是原来的类别苹果。那么我应该在控制器中的哪个文件夹中工作?我想是产品文件夹,但我不确定。我不确定在哪里添加tpl内容,bec因为在controller/product/category.tpl中,它是不同的。您可以在这里找到category.tpl文件:转到catalog>view>theme>default(您的主题)>template>product>category.tpl
    $image = $this->model_tool_image->resize($result['image'], $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height'));
                $this->data['categories'][] = array(
                    'name'  => $result['name'] . ($this->config->get('config_product_count') ? ' (' . $product_total . ')' : ''),
                    'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url), 'thumb' => $image
                );
    
    <div class="category-list">
             <ul class="list-item">
             <?php $counter = 0; foreach ($categories as $category) {?>  
                    <li>
                        <?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 } ?>
                    </li>
            <?php $counter++; } ?>
            </ul>
          </div>