D
D
Dmitry Zorin2021-06-14 13:22:24
PHP
Dmitry Zorin, 2021-06-14 13:22:24

How not to display an empty menu?

<?php if (isset($category['children'][$i]['level3'])) {  $level3menus = $category['children'][$i]['level3']; ?>
              <ul class="level3">
                <?php foreach( $level3menus as $level3menu) {?>
                  <li><a href="<?php echo $level3menu['href']; ?>" class=""><?php echo $level3menu['name'];?></a></li>
                <?php } ?>
              </ul>
            <?php } ?>

There is such a code, it displays the third level menu in the site header (Opencart 1.5)
It works fine, but the problem is that if the 2nd level category has no children, then the 3rd level menu is still displayed, just empty

Is there any way to fix this easily by adding some condition to the code above?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
gian_tiaga, 2021-06-14
@xxoooo

Add !empty, but just add, do not replace isset otherwise there will be an error in the absence of completely 3 levels

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question