Zen Cart Logo
Forums / General Questions / how to get the subcategories linkage or ID by built in function?

how to get the subcategories linkage or ID by built in function?

Views: 888

Results 1 to 4 of 4
17 May 2012, 12:42 PM
#1
loafer avatar

loafer

New Zenner

Join Date:
Apr 2012
Posts:
15
Plugin Contributions:
0

how to get the subcategories linkage or ID by built in function?

Hi All,

I want to create a drop down menu for all subcategories of the current category. And I tried to get the subcategory IDs by the following:

$sub_current_ids=array();
zen_get_subcategories($sub_current_ids,$current_category_id);

However, the $sub_current_ids() only return the string "array"...

What I am missing or doing wrong? Or is there any zen-cart function can get the linkage of all categories of the current category?

Thanks and please help.

Keith

18 May 2012, 1:12 PM
#2
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,085
Plugin Contributions:
56

Re: how to get the subcategories linkage or ID by built in function?

The function needs the array to be passed by reference:

$sub_current_ids=array();
zen_get_subcategories(&$sub_current_ids,$current_category_id);
19 May 2012, 4:20 AM
#3
loafer avatar

loafer

New Zenner

Join Date:
Apr 2012
Posts:
15
Plugin Contributions:
0

Re: how to get the subcategories linkage or ID by built in function?

lat9, Thank you very much!

Now I can get all subcategories IDs and path by the following code:

$sub_current_ids=array();
zen_get_subcategories(&$sub_current_ids, $current_category_id);
$count = count($sub_current_ids);

For ($i=0; $i < $count; $i++)
{
$x = 'cPath=' . $current_category_id . '_' . $sub_current_ids[$i];
echo zen_href_link('index', $x) . '<br>';
}

And the query is in the numberic sort order by IDs:

array[0] http://localhost/loafer/index.php?main_page=index&cPath=23_1
array[1] http://localhost/loafer/index.php?main_page=index&cPath=23_2
array[2] http://localhost/loafer/index.php?main_page=index&cPath=23_3
array[3] http://localhost/loafer/index.php?main_page=index&cPath=23_25
array[4] http://localhost/loafer/index.php?main_page=index&cPath=23_27

How can I make the query in the "correct" sort order? Just like the sort order of category sidebox or site map?

I have been studied in functions_categories.php but don't know what to do next...

$categories_query = "select c.categories_id, cd.categories_name, c.categories_status
                     from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
                     where " . $zc_status . "
                     parent_id = '" . (int)$parent_id . "'
                     and c.categories_id = cd.categories_id
                     and cd.language_id = '" . (int)$_SESSION['languages_id'] . "'
                     order by sort_order, cd.categories_name";

Can anyone help?

Thanks!

21 May 2012, 5:28 AM
#4
loafer avatar

loafer

New Zenner

Join Date:
Apr 2012
Posts:
15
Plugin Contributions:
0

Re: how to get the subcategories linkage or ID by built in function?

Can anyone give me some hints how to do this?