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"> ?>
<li>
<span class="btn btn-navbar">
<?php echo $parent_category->name ?> <i class="fa fa-caret-down" aria-hidden="true"></i>
<ul class="card-menu">
<?php <?php
$categories = get_categories( array( $categories = get_categories( array(
'orderby' => 'name', 'orderby' => 'slug',
'order' => 'ASC' 'order' => 'ASC',
'parent' => $parent_category->term_id
) ); ) );
foreach( $categories as $category ) { foreach( $categories as $category ) {
echo '<li class="nav-item"><a class="nav-link" href="' . get_category_link($category->term_id) . '">' . $category->name . '</a></li>'; if ($category->slug != "chapters") {
}?> echo '<li><a class="menu-element" href="' . get_category_link($category->term_id) . '">' . $category->name . '</a></li>';
}
}
?>
</ul> </ul>
</div> </span>
</nav> </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 @@
<?php
$parent_categories = get_categories( array(
'orderby' => 'slug',
'order' => 'ASC',
'parent' => 0
) );
foreach( $parent_categories as $parent_category ) {
?>
<div class="card card-primary"> <div class="card card-primary">
<div class="card-header"><i class="fa fa-folder" aria-hidden="true"></i> Catégories</div> <div class="card-header"><i class="fa fa-folder" aria-hidden="true"></i> <?php echo $parent_category->name ?></div>
<ul class="card-menu"> <ul class="card-menu">
<?php <?php
$categories = get_categories( array( $categories = get_categories( array(
'orderby' => 'name', 'orderby' => 'slug',
'order' => 'ASC' 'order' => 'ASC',
'parent' => $parent_category->term_id
) ); ) );
foreach( $categories as $category ) { foreach( $categories as $category ) {
if ($category->slug != "blog" && $category->slug != "chapters") { 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>'; 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
}
?>