Your account expired support, please renew to get your support.

Home Forums Themes Support Claue Hide Empty Categories on Menu

Viewing 4 reply threads
  • Author
    Posts
    • #33815
      schris
      Support 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?

    • #33817
      Harry
      Support 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

    • #33820
      schris
      Support 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?

    • #33822
      Harry
      Support 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

      • #34385
        schris
        Support 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?

    • #34388
      Harry
      Support 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

      • #34390
        schris
        Support Expired

        The workaround works fine, many thanks!

Viewing 4 reply threads

You must be logged in to reply to this topic.