category_tree
category_tree — prints nested tree of categories and sub-categories
Summary
category_tree($params);
Default usage
//get all categories
category_tree();
Example with all parameters
// display with all parameters
$params = array();
$params['parent'] = 0; // parent category id
$params['link'] = '<a href="{link}" id="category-{id}">{title}</a>'; // sets the list_item content
$params['active_ids'] = array(5,6); //ids of active categories
$params['active_code'] = "active"; //inserts this code for the active ids's
$params['remove_ids'] = array(1,2); //remove those caregory ids
$params['include_first'] = false; //if true it will include the main parent category
$params['add_ids'] = array(10,11); //if you send array of ids it will add them to the category tree
$params['orderby'] = array('position','asc'); //you can order by ant field ;
$params['list_tag'] = "ul";
$params['list_item_tag'] = "li";
$params['ul_class'] = 'main-category';
$params['li_class'] = 'sub-category';
category_tree($params);
// prints ULs with LIs
Parameters
You can pass parameters as string or as array.
parameter | description | usage |
---|---|---|
parent | you can build tree from a given parent | $params['parent'] = 0; |
link | sets the content of the list item | $params['link'] = '{title}'; // sets the list_item content |
ul_class | sets a class for the UL | $params['ul_class'] = 'nav' |
li_class | sets a class for the LI | $params['li_class'] = 'sub-nav' |
list_tag | you can set custom tag insted of UL | $params['list_tag'] = 'div'; // sets the list main tag |
list_item_tag | you can set custom tag insted of LI | $params['list_item_tag'] = 'span'; // sets the list items tag |
remove_ids | removes certain ids from the tree | $params['remove_ids'] = array(1,2); |
add_ids | sdds certain ids to the tree | $params['add_ids'] = array(5,7); |
active_code | inserts this code for the active ids's | $params['active_code'] = "class='selected'"; |
active_ids | inserts active_code as those ids | $params['active_ids'] = array(3); // sets ids where {active_code} will be inserted |
max_level | if set it will limit the depth of the ree | category_tree(max_level=1'); |