Listing Categories with thumbnails

I am trying to list a list of categories and subcategories on the main_content.override.tpl template, where just the categories will have a small thumb from the categories images uploaded from the back end. I am able to list the category names and the subcategories but i am not being able to display the thumbs.


{foreach from=0|fn_get_subcategories item="cat" name="cat"}

is generating the list of categories…

any ideas?

You would be better off adding a my_changes/controllers/customer/ file and assigning ‘cat’ to fn_get_categories() of the current category (I.e. category_id=1 REQUEST parameter) for the current view.

Depending on the options you pass to fn_get_categories() will determine the amount of info in ‘cat’…

thanks for the reply, I think this is a good idea but i don’t now how i will benefit from it, i explain better. In my case what i want, is to create a drop down menu listing all my categories and subcategories. I have done this using pure smarty code, please see attachment of how it looks like now. I generated what is in the picture with the following smarty:

    {assign var='listitems' value='1'}
    {foreach from=0|fn_get_subcategories item="cat" name="cat"}
  • {$cat.category|escape:html}

  • {foreach from=$cat.category_id|fn_get_subcategories item="subcat" name="subcat"}
  • {$subcat.category|escape:html}

  • {assign var='listitems' value=$listitems+1}
    {if $smarty.foreach.subcat.last}{assign var='jump' value='allow'}{/if}
    {assign var='listitems' value=$listitems+1}
    {if $jump eq 'allow' and $listitems gte '13'}
    {assign var='listitems' value='1'}
    {assign var='jump' value='forb'}


Which is located (For the moment) in addons/my_changes/…/main_content.override.tpl.

I i use a controller, as far as i know it has to be invoked by a dedicated dispatch command, “please, correct me if i am wrong”, thus not usefull.

my problem comes when in that cycle, when fetching the main categories, i try to deal with the image path???

Hope i guide you better through my problem now…


You are itteratively calling a php function fn_get_subcategories for each category. Why don’t you just call fn_get_category_tree() instead? You’re keeping an awful lot of ‘state’. Why don’t you do this recursively which is the natural way to deal with a “tree”?

I’ll have to say that i am not really good using smarty or PHP. This was the faster way i could draw a segmented list of categories and subcategories so my drop down division does not increase too much in height, and a thumbnail could be placed beside each main cat and not the subcategory… I’ll really appreciate a little bit of help on this… An example will help!! thanks again

sorry, can’t write it for you. Can only advise as to what “I would do”.

Thanks for your ideas. I do not want you to write it for me. I just wanted an example on how the image data can be retrieved for a specific category. As you said, is there always an optimum way to do programing. I could, from the smarty code jump to php and query the DB and get the links using the cat id but of course this would not be optimum, this is what i wanted you to guide me through, the way to do it using the smarty vars…

I would not do it through Smarty. I would setup the smarty variables in PHP controller before the view is displayed so the variables would be available. I would provide $cat_tree = fn_get_category_tree(0); Then create a separate file that could be called recursively as the tree is walked.

What I hear is I don’t want to know how it should be done, I want you to help me do it my way… I’m not stating this as a criticism, I just would not do it the way you’re doing it and I can’t afford to take the time to do it for you. Hence, you’re getting free advice, but it won’t be detailed due to the time it would take. Someone else may be willing to guide you though the detail.

No, don’t misunderstand me. I really appreciate your advices. The whole forum is full of your comments and i respect that a lot. Is nice to know that are coders that like to share what they know with those willing to learn.

I’ll give your advice a try with a little bit more of time… thanks again…

how did you ddo attachted menu plase share with me