V
V
Vlad Bazarov2015-04-01 20:56:28
HTML
Vlad Bazarov, 2015-04-01 20:56:28

How to display a subcategory with pictures (Opencart)?

Good evening!
It is necessary that subcategories are displayed with pictures (those that were set in the admin panel). Here is the code of the file where you want to output the files.
OC2.0; File - product/category.tpl

<?php if ($categories) { ?>
      <h3><?php echo $text_refine; ?></h3> 
      <?php if (count($categories) <= 5) { ?>
      
        <section class="choose">
        <article>
            <?php foreach ($categories as $category) { ?>
            
            <img src="<?echo $category['thumb']; ?>"> <!-- Вот эта переменная не находится -->
            <a href="<?php echo $category['href']; ?>"><div><h2><?php echo $category['name']; ?></h2></div></a>
            <?php } ?>
          </article>
        </section>

I'm sure this is easy to do with PHP, but I'm new to it, so I need your help.
The interesting thing is that on the category page everything works, but the subcategories do not.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry Evgrafovich, 2015-04-01
@vlad1337

open catalog/controller/product/category.php and on the 180th line see how the elements of the $data['categories'][] array are set, you will declare thumb there - there will be a picture in the variable. You can see how the pictures are pulled out in the same file in the code above:

if ($category_info['image']) {
        $data['thumb'] = $this->model_tool_image->resize($category_info['image'], $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height'));
      } else {
        $data['thumb'] = '';
      }

by analogy, make an assignment, only from $result, and not from $category_info

V
vlkombat, 2015-12-17
@vlkombat

Here is perhaps another solution - here, in addition to displaying the image, there is also a breakdown of the name into the actual name and the counter of goods. It turns out something like this:
category-isobrazhenie-ico.png

V
Vlad Bazarov, 2015-04-01
@vlad1337

Thanks, Dmitry! Literally a few minutes before your answer, I was able to find the answer over the hill. forum.opencart.com/viewtopic.php?f=21&t=139708 If anyone needs it. Here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question