Answer the question
In order to leave comments, you need to log in
How to make a simple output of categories?
Hello everyone, how exactly can you simplify the code so that the category is simply taken from the database and displayed?
<?php if ($categories) { ?>
<nav id="menu" class="navbar">
<div class="navbar-header"><span id="category" class="visible-xs"><?php echo $text_category; ?></span>
<button type="button" class="btn btn-navbar navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse"><i class="fa fa-bars"></i></button>
</div>
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav">
<?php foreach ($categories as $category) { ?>
<?php if ($category['children']) { ?>
<li class="dropdown"><a href="<?php echo $category['href']; ?>" class="dropdown-toggle" data-toggle="dropdown"><?php echo $category['name']; ?></a>
<div class="dropdown-menu">
<div class="dropdown-inner">
<?php foreach (array_chunk($category['children'], ceil(count($category['children']) / $category['column'])) as $children) { ?>
<ul class="list-unstyled">
<?php foreach ($children as $child) { ?>
<li><a href="<?php echo $child['href']; ?>"><?php echo $child['name']; ?></a></li>
<?php } ?>
</ul>
<?php } ?>
</div>
</div>
</li>
<?php } else { ?>
<li><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a></li>
<?php } ?>
<?php } ?>
</ul>
</div>
</nav>
<?php } ?>
Answer the question
In order to leave comments, you need to log in
Somewhere you have an array of $categories being formed, obviously not in this code. There is no access to the database, html code is formed here.
Judging by the code, this is a bootstrap navbar, which forms a menu from your $categories array. Do you want to have 1 menu item?
See category controller. You can set your own sampling logic by looking at the model of this controller
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question