category_tree — prints nested tree of categories and sub-categories



Default usage

//get all categories

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';
    // prints ULs with LIs


You can pass parameters as string or as array.

parentyou can build tree from a given parent$params['parent'] = 0;
linksets the content of the list item$params['link'] = '{title}'; // sets the list_item content
ul_classsets a class for the UL$params['ul_class'] = 'nav'
li_classsets a class for the LI$params['li_class'] = 'sub-nav'
list_tagyou can set custom tag insted of UL$params['list_tag'] = 'div'; // sets the list main tag
list_item_tagyou can set custom tag insted of LI$params['list_item_tag'] = 'span'; // sets the list items tag
remove_idsremoves certain ids from the tree$params['remove_ids'] = array(1,2);
add_idssdds certain ids to the tree$params['add_ids'] = array(5,7);
active_codeinserts this code for the active ids's$params['active_code'] = "class='selected'";
active_idsinserts active_code as those ids$params['active_ids'] = array(3); // sets ids where {active_code} will be inserted
max_levelif set it will limit the depth of the reecategory_tree(max_level=1');
The documentation is under development. Help us by editing this page.