05.3 Category Functions
Peter Ivanov edited this page Aug 20, 2013
·
1 revision
Those functions works with the the categories
db table.
Returns array of category ids
$categories = get_categories_for_content($content_id=5);
print_r($categories);
Returns array of categories
//get main categories for the content
$categories = get_categories('rel=content&parent_id=0&orderby=position asc');
//you can use the categories functuonality to for your custom data with the `rel` parameter
$modules_categories = get_categories('rel=modules&parent_id=0');
Parameters
parameter | description | usage |
---|---|---|
id | the id of the category | get_categories('id=3'); |
parent_id | the id of the parent category | get_categories('parent_id=0'); |
rel | the category relation to other db table | get_categories('rel=content'); |
rel_id | the item from the related db table |
get_categories('rel=content&rel_id=5'); gets categories for the content with id 5 |
created_by | get by author id | get_categories('created_by=1'); |
created_on | the date of creation |
strtotime compatible date |
updated_on | the date of last edit |
strtotime compatible date |
title | Title of the category | |
content | The html content saved in the database | |
description | Description used for the content list | |
position | The order position | |
users_can_create_content | flag if users can add content in this category | "n" or "y" |
Get single category by id
$category = get_category_by_id($id=1);
Get all sub-categories
$category_children = get_category_children($id=1);
Get link for a category
$category_url = category_link($id=1);
Prints nested tree of categories and sub-categories
$params = array();
$params['parent'] = 0; //parent id
$params['link'] = '<a href="#{id}">{title}</a>'; // the link on for the <a href
$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['ul_class_name'] = 'nav'; //class name for the ul
$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
$params['orderby'] = array('created_on','asc'); //you can order by ant field ;
$params['list_tag'] = 'select';
$params['list_item_tag'] = "option";
category_tree($params);