M
M
mrzgt2015-08-26 10:50:37
User navigation
mrzgt, 2015-08-26 10:50:37

How to substitute in foreach menu?

there is a menu, everything works fine

<div class="menu-wrapper">
            <ul class="obsm">
              <li><a>Home</a></li>
              <li><a>Products</a>
                <ul>
                  <li><a>Books</a></li>
                </ul>
              </li>
            </ul>
          </div>

I'm trying to make it through Php
<div class="menu-wrapper">
          <ul class="obsm">
          <?php foreach ($categories as $category) { ?>
        <li>
          <?php if ($category['category_id'] == $category_id) { ?>
          <a href="<?php echo $category['href']; ?>" class="active"><?php echo $category['name']; ?></a>
          <?php } else { ?>
          <a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
          <?php } ?>
          <?php if ($category['children']) { ?>
          <ul>
            <?php foreach ($category['children'] as $child) { ?>
         
              <?php if ($child['category_id'] == $child_id) { ?>
              <a href="<?php echo $child['href']; ?>" class="active"><?php echo $child['name']; ?></a>
              <?php } else { ?>
              <a href="<?php echo $child['href']; ?>"><?php echo $child['name']; ?></a>
              <?php } ?>
         
            <?php } ?>
          </ul>
          <?php } ?>
        </li>
        <?php } ?>		
            </ul>
          </div>

but in this case they do not want to display subcategories

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
ChernovGV, 2015-08-26
@ChernovGV

What is $child_id?
And there is no tag<li></li>

<ul>
            <?php foreach ($category['children'] as $child) { ?>
         
              <?php if ($child['category_id'] == $child_id) { ?>
              <a href="<?php echo $child['href']; ?>" class="active"><?php echo $child['name']; ?></a>
              <?php } else { ?>
              <a href="<?php echo $child['href']; ?>"><?php echo $child['name']; ?></a>
              <?php } ?>
         
            <?php } ?>
          </ul>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question