• Resolved madla

    (@madla)


    What’s the best way to add the categories under a products tab in the main navigation?
    I don’t want to setup a custom menu but rather automatically insert any categories.

    Can I somehow use the breadcrumbs to accomplish this?

    Thanks in advance.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author sparkweb

    (@sparkweb)

    There’s a function you can use called foxyshop_simple_category_children() which will show a list of categories. Read about it here: https://www.foxy-shop.com/2011/06/version-2-7-variation-upgrades-and-other-tweaks/

    Thread Starter madla

    (@madla)

    That works great for single hierarchy. How would I go about getting subcategories?

    Do I have to loop through them via:
    get_terms(‘foxyshop_categories’, ‘hide_empty=0&hierarchical=0&parent=0&orderby=name&order=ASC’)

    I tried changing hierarchical to 1 and tried by going just after a parent id.

    foxyshop_simple_category_children(parentid) works if I loop through the top hierarchy but then it returns already in a list.

    Plugin Author sparkweb

    (@sparkweb)

    I think in this case I would do get_terms and then inside that loop, I would do get_term_children (https://codex.www.ads-software.com/Function_Reference/get_term_children) for showing the children of each of the top-levels. You might have to do that a few times if you have more than two levels.

    Plugin Author sparkweb

    (@sparkweb)

    Never mind, there’s a much better way to do it. You can just do wp_list_categories(“taxonomy=foxyshop_categories”). I think that will do it. Codex: https://codex.www.ads-software.com/Template_Tags/wp_list_categories

    Thread Starter madla

    (@madla)

    Any idea why I’m only getting on of the top categories returned with wp_list_categories?

    echo '<ul class="menu FoxyShop_Show_Categories_widget">';
    echo wp_list_categories("taxonomy=foxyshop_categories&title_li=&depth=2");
    echo '</ul>';
    Plugin Author sparkweb

    (@sparkweb)

    I tested this and it showed all my categories. One thing to keep in mind: by default it will only show categories that have something in them. Check the specs at https://codex.www.ads-software.com/Template_Tags/wp_list_categories and try adding &hide_empty=0

    Hi guys,

    Thanks for the comments here – this is exactly what I was looking at doing this week. One limitation I’ve found with calling wp_list_categories is that we lose the Foxy Shop sorting/ordering setting. Any ideas on a work around?

    Plugin Author sparkweb

    (@sparkweb)

    You can do foxyshop_simple_category_children($parent_category_id) but it won’t show the sub-categories. Although I suppose it’s possible that it could be tweaked to do that. Do you need sub-categories? If you just want to show top-level cats, you can do this:

    foxyshop_simple_category_children(0)

    Plugin Author sparkweb

    (@sparkweb)

    I re-wrote the internal foxyshop function to call this and added levels. This will be available with the next version (3.2). For now, go into helperfunctions.php and remove the function around line 611 called foxyshop_simple_category_children. Replace it with the code from https://pastie.org/private/hz9egddbswonul7ofkaewa

    Now you can do this:

    echo '<ul class="menu FoxyShop_Show_Categories_widget">';
    foxyshop_simple_category_children(0, -1);
    echo '</ul>';

    …to show all categories nested and using proper order. If you just want to do 2 levels, change the second argument from -1 to 2.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Adding product categories to main navigation’ is closed to new replies.