Forums / Templates, Stylesheets, Page Layout / Showing subcategories on the index page

Showing subcategories on the index page

Views: 12,596

Results 1 to 20 of 43
11 Apr 2007, 6:27 PM
#1
pm_vibes avatar

pm_vibes

New Zenner

Join Date:
Apr 2007
Posts:
7
Plugin Contributions:
0

Showing subcategories on the index page

Hi all

The normal behaviour of Zen Cart is that you see the subcategories of a category when you click on the category itself (and it opens the relative category page).
Since I've got only two top-categories on my site, I need that a visitor could see the complete list of subcategories on the sidebox immediately when he opens the site, on the index page.
I've tried to make it by myself but the sidebox code (tpl_categories, categories, category_tree, etc.) seems to be a little too complicated to understand so I don't know exactly how to change it for my purpose. :(

Thanks a lot...

11 Apr 2007, 6:56 PM
#2
haredo avatar

haredo

Totally Zenned

Join Date:
Apr 2006
Location:
Texas
Posts:
6,185
Plugin Contributions:
0

Re: Showing subcategories on the index page

Try this:

You half to download a module to create the effect you are trying.

http://www.zen-cart.com/index.php?ma...roducts_id=392

Mark,

Need a hand with Zen Cart? Hire the team at myZenCartZone.com for upgrades, repairs, and custom plugins.

Zen Cart Certified hosting at myZenCartHost.com.

11 Apr 2007, 7:53 PM
#4
pm_vibes avatar

pm_vibes

New Zenner

Join Date:
Apr 2007
Posts:
7
Plugin Contributions:
0

Re: Showing subcategories on the index page

THANKS!!

It works!

And I've just found that if you don't want to display also products but only subcategories (like me) you have only to comment this line on class category_list.php:

$this->build_products($category_id, $category_link,$level);

:smile:

11 Apr 2007, 7:55 PM
#5
haredo avatar

haredo

Totally Zenned

Join Date:
Apr 2006
Location:
Texas
Posts:
6,185
Plugin Contributions:
0

Re: Showing subcategories on the index page

Sweet,
Thanks for the update.
Nifty idea.

Mark

Need a hand with Zen Cart? Hire the team at myZenCartZone.com for upgrades, repairs, and custom plugins.

Zen Cart Certified hosting at myZenCartHost.com.

15 Apr 2007, 2:55 PM
#6
pm_vibes avatar

pm_vibes

New Zenner

Join Date:
Apr 2007
Posts:
7
Plugin Contributions:
0

Re: Showing subcategories on the index page

There's a problem with the Expanded Category Sidebox...
it doesn't show the category tree correctly.

For ex. if the categories are:

Cat1

Subcat1
Subsubcat1
Subsubcat2
Subsubcat3

Subcat2
Subcat3

Cat2
Subcat4
Subcat5

the sidebox list them like this:

Cat1

Subcat1
Subsubcat1

Subsubcat2
Subsubcat3
SubCat2
SubCat3
Cat2
Subcat4
Subcat5

I think there's some mistakes on the class category_list.php but I can't fix them very easily...

:(

15 Apr 2007, 7:58 PM
#7
savaradu avatar

savaradu

New Zenner

Join Date:
Apr 2007
Posts:
4
Plugin Contributions:
0

Re: Showing subcategories on the index page

I want to show 10 products of each category on first page .
Can u help me ?

16 Apr 2007, 12:28 PM
#8
savaradu avatar

savaradu

New Zenner

Join Date:
Apr 2007
Posts:
4
Plugin Contributions:
0

Re: Showing subcategories on the index page

On my wesite i have 10 categories without subcategories, the products are in categories. I want to show on the first page 10 products of each category, how can i do that ?

25 Apr 2007, 7:32 PM
#9
rlesiak avatar

rlesiak

New Zenner

Join Date:
Apr 2007
Posts:
2
Plugin Contributions:
0

Re: Showing subcategories on the index page

hi,

i tried installing this fix and it doesn't seem to work. does anybody have any suggestions? i know the files have been uploaded to the right place but i'm afraid i may have an override or admin somewhere that's not letting it work.

the site is here:

http://www.tracygloverstudio.com/shop

any help really appreciated - thanks

rebecca

27 Apr 2007, 8:55 PM
#10
zkitten avatar

zkitten

New Zenner

Join Date:
Apr 2007
Posts:
19
Plugin Contributions:
0

Re: Showing subcategories on the index page

I followed the same directions as PM Vibe,
and I am having the same problam,

my catagories are showing like this

** cat1**

subcat1
subcat2
cubcat3

** cat2**

subcat1
subcat2
subcat3
subcat4

the code I currenrlty have in category_lsit.php

any help would be appriciated :)

class category_list {    
    var 
        $root_category_id = 0,
        $max_level = 0,
        $data = array(),
        $box_categories_array=array(); 
    
    function category_list() {
        global $languages_id, $db;
        $this->icount=0;
        $this->box_categories_array=array();
        $this->data = array();
        $categories_query = "select c.categories_id, cd.categories_name, c.parent_id
                       from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
                       where c.categories_id = cd.categories_id
                       and cd.language_id = '" . (int)$_SESSION['languages_id'] . "'
                       order by c.parent_id, c.sort_order, cd.categories_name";
        $categories = $db->Execute($categories_query);
        while (!$categories->EOF) {        
            $this->data[$categories->fields['parent_id']][$categories->fields['categories_id']] = 
                array('name' => $categories->fields['categories_name'], 'count' => 0);
            $categories->MoveNext();
        }        
    }
  
    function build_branch($parent_id, $level = 0, $parent_link = ''){
        $box_categories_array = & $this->box_category_array;
        $icount = & $this->icount;
        if (!isset($this->data[$parent_id])){ 
            return;
        }
        //next id not used
        $box_categories_array[$icount]['next_id']=false;
        $box_categories_array[$icount]['is_product']=false;
        $box_categories_array[$icount]['level']=$level;
        foreach ($this->data[$parent_id] as $category_id => $category){ 
            if ($parent_id == 0){ 
                $box_categories_array[$icount]['top']='true';
            }else{
                $box_categories_array[$icount]['top']='false';
            }
            $category_link = 'cPath='. $parent_link.$category_id;             
            $box_categories_array[$icount]['path'] = $category_link;
            $box_categories_array[$icount]['name'] = $category['name'];
            $box_categories_array[$icount]['count'] = zen_count_products_in_category($category_id) ;
            // this doesn't work :(
            if($category_id == $current_category_id){
                $box_categories_array[$icount]['current']=true;
            }else{
                $box_categories_array[$icount]['current']=false;
            }
            if (isset($this->data[$category_id])) { 
                $box_categories_array[$icount]['has_sub_cat'] = true; 
            } else {
                $box_categories_array[$icount]['has_sub_cat'] = false; 
            }
            $box_categories_array[$icount]['category_id'] = $category_id;
            $icount++;
/*            $this->build_products($category_id, $category_link,$level);    */
            if (isset($this->data[$category_id]) && (($this->max_level == '0') || ($this->max_level > $level+1))) {
                $this->build_branch($category_id, $level+1, $category_link . '_');    
            } 
        }        
        return  $box_categories_array;
    }
    
    function build_products($category_id, $category_link, $level){
        global $languages_id, $db;
        $box_categories_array = & $this->box_category_array;
        $icount = & $this->icount;
        $products_query = "SELECT ". TABLE_PRODUCTS .".products_id, products_name 
            FROM ". TABLE_PRODUCTS." 
            INNER JOIN ". TABLE_PRODUCTS_DESCRIPTION ." 
                ON ". TABLE_PRODUCTS .".products_id = ". TABLE_PRODUCTS_DESCRIPTION .".products_id 
            WHERE (((". TABLE_PRODUCTS_DESCRIPTION .".language_id)=". (int)$_SESSION['languages_id'] .") 
                AND ((". TABLE_PRODUCTS .".master_categories_id)=". $category_id ."))
            ORDER BY ". TABLE_PRODUCTS .".products_sort_order, ". TABLE_PRODUCTS_DESCRIPTION .".products_name";
        $products = $db->Execute($products_query);
        if (!$products->EOF){
            while (!$products->EOF){        
                $box_categories_array[$icount]['count'] = 0 ;
                $box_categories_array[$icount]['level']=$level;
                $box_categories_array[$icount]['top']='false';
                $box_categories_array[$icount]['is_product']=true;
                $box_categories_array[$icount]['has_sub_cat'] = false;
                $box_categories_array[$icount]['name']=$products->fields['products_name'];
                $box_categories_array[$icount]['path']= 'cPath=' . $category_link ."&products_id=".$products->fields['products_id'] ;
                $box_categories_array[$icount]['products_id']=$products->fields['products_id'] ;
                //this doesn't work :(
                if ($products->fields['products_id'] == $products_id){
                    $box_categories_array[$icount]['current']=true;
                }else{
                    $box_categories_array[$icount]['current']=false;
                }
                $products->MoveNext();
                $icount++;
            }  
        }
        return $result;
    }    
    
    function build_list() {
        return $this->build_branch($this->root_category_id);
    }        
}  
28 Apr 2007, 2:22 AM
#11
fakedecoy avatar

fakedecoy

Zen Follower

Join Date:
Jul 2006
Posts:
309
Plugin Contributions:
0

Re: Showing subcategories on the index page

I'm interested in doing this same thing, so I'm hoping there's a solution for this.

Adamant Barbell - Home & commercial gym equipment - Since 2007
www.adamantbarbell.com

28 Apr 2007, 2:33 AM
#12
zkitten avatar

zkitten

New Zenner

Join Date:
Apr 2007
Posts:
19
Plugin Contributions:
0

Re: Showing subcategories on the index page

Until I can get an awnser,
I've changed my set up a little like this-

cat1 (diffrent backround color)
subcat1
subcat2
subcat3
cat2 (diffrent backround color)
subcat1
subcat2
subcat3
subcat4

Which is working ok for now, but I would reallly rather have the indented sub-categories, It just looks nicer ;)

28 Apr 2007, 5:47 AM
#13
pm_vibes avatar

pm_vibes

New Zenner

Join Date:
Apr 2007
Posts:
7
Plugin Contributions:
0

Re: Showing subcategories on the index page

I've contacted the author of the sidebox, Clyde Jones, some days ago.

He's working on the solution, then will post here when he fixes the problem.

So we only have to wait some days :wink:

28 Apr 2007, 5:43 PM
#14
zkitten avatar

zkitten

New Zenner

Join Date:
Apr 2007
Posts:
19
Plugin Contributions:
0

Re: Showing subcategories on the index page

AWESOME!
I've been trying to figure out all my problams by searching the FAQ, googling, and forums, but this got me stumped!

1 May 2007, 5:21 PM
#15
clydejones avatar

clydejones

Deceased

Join Date:
Nov 2005
Location:
Colorado Springs, CO USA
Posts:
7,017
Plugin Contributions:
12

Re: Showing subcategories on the index page

PM Vibes:

I've contacted the author of the sidebox, Clyde Jones, some days ago.

He's working on the solution, then will post here when he fixes the problem.

So we only have to wait some days :wink:

I've gone cross eyed and gotten a massive headache.

I've gone through the code for the past three days trying to figure out where the glitch is. I've tried several different fixes and permutations and so far -NADA!

If anyone else wants to try their hand, I'd sure welcome the help.

NOTE: We are sorry that Clyde is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

1 May 2007, 11:06 PM
#16
zkitten avatar

zkitten

New Zenner

Join Date:
Apr 2007
Posts:
19
Plugin Contributions:
0

Re: Showing subcategories on the index page

I've gone through everything I can think of myself..
I'll keep seeing if I can find something as well :)

13 May 2007, 5:23 PM
#17
fakedecoy avatar

fakedecoy

Zen Follower

Join Date:
Jul 2006
Posts:
309
Plugin Contributions:
0

Re: Showing subcategories on the index page

Any luck on this? Or did Clyde Jones do anything?

Adamant Barbell - Home & commercial gym equipment - Since 2007
www.adamantbarbell.com

13 May 2007, 7:17 PM
#18
zkitten avatar

zkitten

New Zenner

Join Date:
Apr 2007
Posts:
19
Plugin Contributions:
0

Re: Showing subcategories on the index page

I just went back to the default look of the categories, I had no luck.

13 May 2007, 7:27 PM
#19
fakedecoy avatar

fakedecoy

Zen Follower

Join Date:
Jul 2006
Posts:
309
Plugin Contributions:
0

Re: Showing subcategories on the index page

I looked at it too, and I was pretty baffled that what I tried didn't work. It seems like there should just be some variable in there that some code can be added for to make it think all main categories are the one currently selected so that it expands them, you know?

But if we rabble rabble rabble about it enough, I think someone will come up with a change. There's probably a lot of people who would like to do it, as other types of website engines display their categories expanded like that.

Adamant Barbell - Home & commercial gym equipment - Since 2007
www.adamantbarbell.com

13 May 2007, 7:38 PM
#20
zkitten avatar

zkitten

New Zenner

Join Date:
Apr 2007
Posts:
19
Plugin Contributions:
0

Re: Showing subcategories on the index page

Going back to the default, I did get a look I'm happy with for now (it's here)

I may actualy set up another cart just for trying to figure things out and learning php a little better. (because the store I currently have is live)
Getting that category listing style is definatly in my top to figure out!