Anybody could help to generate root categories for top menu dynamically? When I add a category to top menu through admin the category is not displayed as selected if any of its subcategories or products are selected.
When you click on a subcategory in the categories box or any submenu the root category for that subcategory if it is in the top menu is no longer displayed as highlighted (off). Also when a user clicks on any product he does not know which category or subcategory the product belongs to (unless he looks for breadcrumbs which are small and intended mostly for search engines anyway). If dynamic categories menu box is enabled the cat tree collapses each time a product page is displyed instead of highlighting the subcategory for that product. This makes navigation more difficult and confusing.
On my current website (v1.3) the top meny displays only root categories. Instead of adding them manually through admin they are generated automatically using the code similar to this in top_menu.tpl:
Say you have three root categories: books, computers, dvd. If you add them all to the top menu using admin and use views you are referring to, the program would not recognize which of those categories a certain product belongs to. I already tried it. It highlights only the first category you select and then gets stuck there. Try it. Add three categories to the top menu and then click on various featured products in your home page. Will the top menu highlight the correct category for each product you select? If you have dynamic menu enabled through blocks for you categories box will it highlight the subcategory for that product in the expanded category tree or will the tree collapse?
Check deepdiscount.com and see how their top categories work for different products.
I don’t use featured products so can’t duplicate here. But if the “view” is in the list of “Activate tab menu for” then it will highlight the tab. I.e. if ‘featured products’ resolves to a dispatch=products.view then the tab will be highlighted. If it resolves to some other controller/mode then simply list that controller.mode in the “Activate tab menu for” input box.
If you have three categories: books, computers, dvd in your top menu, and you have product view enabled, the program has absolutely no clue which category the product belongs to. You click on books in the top menu - books get highlighted. If later on you start viewing other products - computers, dvds or apparel you will still get books category highlighted in the top menu which is wrong and confusing… If the first one you clicked was computers tab in the top menu - you will get computers tab highlighted even if you are viewing books or underwear.
My main question is though: why the piece of code I mentioned earlier does not work in the top_menu.tpl? Looks like it does not call categories function at all. This v2 is a lot harder to modify for simple things like this one…
After I changed the code in the top_menu.tpl it still shows the previous ctaegory (the one clicked on before I replaced the piece of code (computers), I even tried to clean the blocks cache, but may be another cache shoud be cleaned too):
Got it! Though this solution is to show expanded category tree when viewing product details page (see the third image) and not for the top menu. Now I can certainly find a workaround for the top menu categories by just rewriting the code in the hook.
function fn_get_categories($params = array(), $lang_code = CART_LANGUAGE)
$category_id = db_get_field(“SELECT ?:products_categories.category_id FROM ?:products_categories LEFT JOIN ?:categories ON ?:categories.category_id=?:products_categories.category_id WHERE ?:products_categories.product_id=‘$product_id’”); [/COLOR]
I wouldn’t be messing with fn_get_categories()… It is controlled by the parameters passed to it which vary widely depending on what area of the system is asking for category information… You might solve this specific issue, but may impact other operations that are not obvious at this point.
I’m trying to do something similar. I want to put the category list in the side nav and the footer. However, when I put the foreach command in the footer, nothing happens, though it works in the side nav. Anybody able to explain this? I’m new to smarty, so there might be something I am missing.
This code works in menu_items.tpl, but not in other templates: