Global Product Category List - Dropdown and show empty categories

Hello, for global category list there are limited optional attributes:

[mp_global_categories_list] - Displays a network-wide HTML list of product categories according to preference.
Optional Attributes:
"limit" - Text to display for showing all categories. Default: 50
"order_by" - What column to use for ordering the categories. "count" or "name". Default: count
"order" - Direction to order products by. Can be: DESC, ASC. Default: DESC
"show_count" - Whether to show how many posts are in the category. Default: 0
"include" - What to show, "tags", "categories", or "both".
Example: [mp_global_categories_list limit="30" order_by="name" order="ASC" show_count="1" include="both"]

I would like to know
1. How I can change the list to be a drop-down list
2. How to show only one specific global category and all the sub-categories below it, including the empty ones.

also, I have two more questions that are unanswered from my previous post:

Post here
Thank you

  • Ash
    • WordPress Hacker

    Hello @Tzer-yen

    Welcome to WPMU community!

    I hope you are well today and thanks for asking the question.

    1. How I can change the list to be a drop-down list

    You have to change the HTML in /plugins/marketpress/marketpress-includes/marketpress-ms.php line no 1164 - function mp_global_categories_list.

    2. How to show only one specific global category and all the sub-categories below it, including the empty ones.

    To include empty ones, remove the following from line 1208:

    if ( $tag['count'] == 0 )
    			continue;

    Please note that, this changes will be lost in next update. So it's worth to note down this changes somewhere and apply again after your updates.

    To show only one specific global category and all the sub-categories below it - do you mean you don't want to show all global parent categories? Just one single category and it's child categories?

    Please let us know.

    Cheers
    Ash

    • Tzer-yen
      • Design Lord, Child of Thor

      To show only one specific global category and all the sub-categories below it - do you mean you don't want to show all global parent categories? Just one single category and it's child categories?

      Yes, that is my intention, thanks!

  • Tzer-yen
    • Design Lord, Child of Thor

    1. How I can change the list to be a drop-down list
    You have to change the HTML in /plugins/marketpress/marketpress-includes/marketpress-ms.php line no 1164 - function mp_global_categories_list.

    Can you please explain what I need to change inside the function?

    To include empty ones, remove the following from line 1208:
    if ( $tag['count'] == 0 )
    continue;

    I tried removing this line but the empty categories are still not showing. By empty I mean the ones without any products. There is an optional shortcode attribute for non-global category but not for global category. Same for drop-down.
    Thanks.

  • Vinod Dalvi
    • WP Unicorn

    Hi @Tzer-yen,

    [mp_global_categories_list] - Displays a network-wide HTML list of product categories according to preference.

    1. How I can change the list to be a drop-down list

    We have discussed your above question in the live chat and to achieve it try using the attached small plugin by network activating it or add the code from the plugin in to the functions.php file of your child theme.

    Best Regards,
    Vinod Dalvi

  • Tzer-yen
    • Design Lord, Child of Thor

    Hi @Vinod Dalvi, thanks for your help on the live chat. There are still some functions that I would like to achieve from the dropdown. First, I want to display the empty categories (i.e. the ones without any products yet) inside the dropdown as well. Second, I want to display only one category and all the sub-categories underneath it.
    For example, I have three categories A,B,C on the same hierarchy level, but I only want to display category B and all the sub-categories underneath it.
    Thanks again for your help! I really appreciate it.

  • Vinod Dalvi
    • WP Unicorn

    Hi @Tzer-yen,

    To achieve your additional requirements, try using the new updated plugin attached to this reply.

    You have to use the shortcode mp_global_categories_list as following using category_id argument where you can define the category id which you want to display and also it will display sub-categories of it.

    [mp_global_categories_list category_id="45"]

    Regards,
    Vinod Dalvi

  • Tzer-yen
    • Design Lord, Child of Thor

    @Vinod Dalvi
    This is working exactly as I wanted! Thank you so much! except one small part, the top category show count is always showing zero despite the subcategories having products. I am not sure if that was intended, but I thought the default was to show the sum of all the subcategories' products count.

  • Ash
    • WordPress Hacker

    Hello @Tzer-yen

    I hope you are well today.

    the top category show count is always showing zero despite the subcategories having products.

    Yes, that is how wordpress handles the post count per category by default. I am tagging @Vinod Dalvi if there is any way to make the sum of child categories for the parent item.

    Cheers
    Ash

  • Vinod Dalvi
    • WP Unicorn

    Hi @Tzer-yen,

    Yes what you and my colleague Ashok said is correct that each category displays the count of posts attached to them directly and not to the sub categories.

    To display the count of subcategories try using the attached modified custom plugin.

    Cheers,
    Vinod Dalvi

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.