donglang2010 2016-10-24 13:15
浏览 48
已采纳

将图像添加到子类别而不是文本链接PHP-OPENCART

I am new to php, same with the opencart. I want to add image w/ link instead of the traditional list of links.

http://www.metroingeni.ro/aparatura/cantare-si-sisteme-de-cantarire

Example of where i want to implement.

  • 写回答

1条回答 默认 最新

  • dsgk0386 2016-10-24 18:34
    关注

    Ok, think I understand what you seek.

    First you need to find a controller that is responsible for category view, you can find it (I assume it's OC2) in catalog/controller/product/category.php file. Somewhere around line 160 you will see:

    $data['categories'][] = array(
        'name' => $result['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
        'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url)
    );
    

    replace it with

    $data['categories'][] = array(
        'name' => $result['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
        'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url),
        'image'=> $result['image']
    );
    

    then in your category view, located at catalog/view/theme/default/template/product/category.tpl somewhere around line 35 and 45, you can place the category image which we got from the controller earlier in a form like <?php echo $category['image']; ?>.


    <?php echo $category['image']; ?> in your view category.tpl is a relative URL of the image. Put it in your image source attribute. Must be within foreach loop of categories.

    Hope this helps, I have not tested this code but it should work.

    Default installation of opencart 2 is here assumed, but the concept should apply to any or most themes or extensions.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀