feat: mutli-categories

This commit is contained in:
Kazhnuz 2023-03-12 16:15:46 +01:00
parent af058e2d8c
commit 365781adbc
3 changed files with 60 additions and 49 deletions

View file

@ -1,19 +1,33 @@
<nav class="navbar navbar-expand-lg navbar-dark bg-grey" id="navbar-category"> <?php
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> $parent_categories = get_categories( array(
<span class="navbar-toggler-icon"></span> 'orderby' => 'slug',
</button> 'order' => 'ASC',
'parent' => 0
) );
<div class="collapse navbar-collapse" id="navbarSupportedContent"> foreach( $parent_categories as $parent_category ) {
<ul class="navbar-nav nav-justified w-100"> ?>
<?php <li>
$categories = get_categories( array( <span class="btn btn-navbar">
'orderby' => 'name', <?php echo $parent_category->name ?> <i class="fa fa-caret-down" aria-hidden="true"></i>
'order' => 'ASC'
) );
foreach( $categories as $category ) { <ul class="card-menu">
echo '<li class="nav-item"><a class="nav-link" href="' . get_category_link($category->term_id) . '">' . $category->name . '</a></li>'; <?php
}?> $categories = get_categories( array(
</ul> 'orderby' => 'slug',
</div> 'order' => 'ASC',
</nav> 'parent' => $parent_category->term_id
) );
foreach( $categories as $category ) {
if ($category->slug != "chapters") {
echo '<li><a class="menu-element" href="' . get_category_link($category->term_id) . '">' . $category->name . '</a></li>';
}
}
?>
</ul>
</span>
</li>
<?php
}
?>

View file

@ -5,24 +5,7 @@
<i class="fa fa-home" aria-hidden="true"></i><span class="sr-only">Accueil</span> <i class="fa fa-home" aria-hidden="true"></i><span class="sr-only">Accueil</span>
</a> </a>
</li> </li>
<li> <?php include(TEMPLATEPATH . '/components/navbar-category.php'); ?>
<span class="btn btn-navbar">
Catégories <i class="fa fa-caret-down" aria-hidden="true"></i>
<ul class="card-menu">
<?php
$categories = get_categories( array(
'orderby' => 'name',
'order' => 'ASC'
) );
foreach( $categories as $category ) {
if ($category->slug != "blog" && $category->slug != "chapters") {
echo '<li><a class="menu-element" href="' . get_category_link($category->term_id) . '">' . $category->name . '</a></li>';
}
}?>
</ul>
</span>
</li>
<?php <?php
$listmenu = get_nav_menu_locations(); $listmenu = get_nav_menu_locations();
$menu = wp_get_nav_menu_items($listmenu['top-navbar']); $menu = wp_get_nav_menu_items($listmenu['top-navbar']);

View file

@ -1,16 +1,30 @@
<div class="card card-primary"> <?php
<div class="card-header"><i class="fa fa-folder" aria-hidden="true"></i> Catégories</div> $parent_categories = get_categories( array(
<ul class="card-menu"> 'orderby' => 'slug',
<?php 'order' => 'ASC',
$categories = get_categories( array( 'parent' => 0
'orderby' => 'name', ) );
'order' => 'ASC'
) );
foreach( $categories as $category ) { foreach( $parent_categories as $parent_category ) {
if ($category->slug != "blog" && $category->slug != "chapters") { ?>
echo '<li><a class="menu-element" href="' . get_category_link($category->term_id) . '">' . $category->name . '<span class="menu-label label-secondary">'. $category->count . '</span></a></li>'; <div class="card card-primary">
<div class="card-header"><i class="fa fa-folder" aria-hidden="true"></i> <?php echo $parent_category->name ?></div>
<ul class="card-menu">
<?php
$categories = get_categories( array(
'orderby' => 'slug',
'order' => 'ASC',
'parent' => $parent_category->term_id
) );
foreach( $categories as $category ) {
if ($category->slug != "chapters") {
echo '<li><a class="menu-element" href="' . get_category_link($category->term_id) . '">' . $category->name . '<span class="menu-label label-secondary">'. $category->count . '</span></a></li>';
}
} }
}?> ?>
</ul> </ul>
</div> </div>
<?php
}
?>