Home › Forums › Themes Support › Claue › Hide Empty Categories on Menu
Tagged: #menu, categories, woocommerce
- This topic has 6 replies, 2 voices, and was last updated 5 years ago by schris.
-
AuthorPosts
-
-
September 24, 2019 at 8:50 pm #33815schrisSupport Expired
Hey there,
I would like empty categories and/or subcategories not to appear in the menus. If I use a custom function in the claue-child functions.php such as this:
add_filter( ‘wp_get_nav_menu_items’, ‘nav_remove_empty_category_menu_item’, 10, 3 );
function nav_remove_empty_category_menu_item ( $items, $menu, $args ) {
global $wpdb;
$nopost = $wpdb->get_col( “SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE count = 0” );
foreach ( $items as $key => $item ) {
if ( ( ‘taxonomy’ == $item->type ) && ( in_array( $item->object_id, $nopost ) ) ) {
unset( $items[$key] );
}
}
return $items;
}Then I get the desired effect, but hierarchy is lost (ie all categories/subcategories with items show up in menu).
Is it possible to keep hierarchy but still hide empty categories?
-
September 24, 2019 at 10:48 pm #33817HarrySupport Expired
Hi Schris,
Thank you for choose our theme.
Please go to Appearance > Widget > WooCommerce Categories Menu Sidebar and follow this screenshot https://prnt.sc/padeqg
Kind regards
Harry
Premium Wordpress themes and plugins, Best WooCommerce theme https://themeforest.net/user/janstudio/portfolio?ref=janstudio -
September 25, 2019 at 4:13 pm #33820schrisSupport Expired
Hi Schris, Thank you for choose our theme. Please go to Appearance > Widget > WooCommerce Categories Menu Sidebar and follow this screenshot https://prnt.sc/padeqg Kind regards
Many thanks for your quick response. Your suggestion works fine for the menu inside the /store page, but on the “main” page, all categories appear. You will see it if you go to the /store page on the website (store menu does not have empty categories, main menu does). So now my question becomes: How can I use the widget as the “main” menu?
-
September 25, 2019 at 4:37 pm #33822HarrySupport Expired
Hi,
I’m sorry the main menu doesn’t support use widget.
On main menu you can control which menu item show, you can remove the empty categories from menu in Appearance > Menus
Harry
Premium Wordpress themes and plugins, Best WooCommerce theme https://themeforest.net/user/janstudio/portfolio?ref=janstudio-
November 6, 2019 at 8:36 pm #34385schrisSupport Expired
Thanks for the reply. As you know, your solution is not automatic (so empty categories still show up until you remove them), which is what I would like to have.
From what I see in the code, the main menu uses JAS_Claue_Menu_Walker, is it possible to change a parameter there so that empty elements are not returned?
-
-
November 7, 2019 at 8:37 am #34388HarrySupport Expired
Hi Schris,
Unfortunately, this cannot be done automatically for menu items.
This have another way is copy header layout running on your site layout-x.php in claue > views > header to claue-child > views > header
and add below code to claue-child > function
function jas_claue_child_register_sidebars() { register_sidebar( array( 'name' => esc_html__( 'Custom Menu Sidebar', 'claue' ), 'id' => 'custom-menu-sidebar', 'description' => esc_html__( 'The custom menu Sidebar', 'claue' ), 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 'after_widget' => '</aside>', 'before_title' => '<h4 class="widget-title fwm">', 'after_title' => '</h4>', ) ); } add_action( 'widgets_init', 'jas_claue_child_register_sidebars' );
and add below code to layout-x.php in claue-child > views > header where you want show menu
<?php if ( is_active_sidebar( 'custom-menu-sidebar' ) ) : ?> <div class="shop-top-sidebar"> <?php if ( ! function_exists( 'dynamic_sidebar' ) || ! dynamic_sidebar( 'custom-menu-sidebar' ) ) : endif; ?> </div> <?php endif; ?>
And go to Appearance > Widget add Product Categories Menu to The Custom Menu Sidebar
Kind regards
Harry
Premium Wordpress themes and plugins, Best WooCommerce theme https://themeforest.net/user/janstudio/portfolio?ref=janstudio
-
-
AuthorPosts
You must be logged in to reply to this topic.