WordPress.org

Forums

FoxyShop
[resolved] Adding product categories to main navigation (10 posts)

  1. madla
    Member
    Posted 4 years ago #

    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.

  2. sparkweb
    Member
    Plugin Author

    Posted 4 years ago #

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

  3. madla
    Member
    Posted 4 years ago #

    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.

  4. sparkweb
    Member
    Plugin Author

    Posted 4 years ago #

    I think in this case I would do get_terms and then inside that loop, I would do get_term_children (http://codex.wordpress.org/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.

  5. sparkweb
    Member
    Plugin Author

    Posted 4 years ago #

    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: http://codex.wordpress.org/Template_Tags/wp_list_categories

  6. madla
    Member
    Posted 3 years ago #

    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>';
  7. sparkweb
    Member
    Plugin Author

    Posted 3 years ago #

    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 http://codex.wordpress.org/Template_Tags/wp_list_categories and try adding &hide_empty=0

  8. creativeworldstudio
    Member
    Posted 3 years ago #

    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?

  9. sparkweb
    Member
    Plugin Author

    Posted 3 years ago #

    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)

  10. sparkweb
    Member
    Plugin Author

    Posted 3 years ago #

    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 http://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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags