GeniXCMS

Categories Class

categoryAPI edit_calendar31 Mar 2026

Categories Class


This class is to manage the Categories. This category structure is very simple.

An improvement probably added in the future. Below are the explanation each method at the Categories Class.

Dropdown Method

Usage : echo Categories::dropdown(array $vars);

Return: string

This method to create an automatic dropdown options from available categories at the database. It means we can create dropdown so easy, just fill in the parameters and a select input created automatically.

Example:

$vars = array(
             'name'      =>  'catname',
             'parent'    =>  'parent',
             'order_by'  =>  '',
             'sort'      =>  'ASC',
           )
echo Categories::dropdown($vars);

That methods calls will create output like this.

<select name="catname" class="form-control">
    <option></option>
    <option value="1">Category Name</option>
    ...
</select>

Explanation:

  • name, this is the name of the select input.
  • parent, this is the parent of the category you want to show. No parent or empty means all categories will shows up.
  • order_by, this is how you want the category ordered by. Available columns are : id, name, slug, parent, desc default is id
  • sort, this is the options how your categories sorted, Ascending ASC, or Descending DESC. Default is ASC

See also:

Lists Method

Usage : echo Categories::lists(array $vars)

This method will show the list of the Categories and Subcategories with the unordered list markup.

example:

$vars = array(
             'parent'    =>  'parent',
             'order_by'  =>  '',
             'sort'      =>  'ASC',
           )
echo Categories::lists($vars);

Explanation:

  • parent, this is the parent of the category you want to show. No parent or empty means all categories will shows up.
  • order_by, this is how you want the category ordered by. Available columns are : id, name, slug, parent, desc default is id
  • sort, this is the options how your categories sorted, Ascending ASC, or Descending DESC. Default is ASC

See also:

Name Method

Usage: echo Categories::name(int '$id');

Return: string

This method will get the name of Category for the specific ID.

example:

we have a list of categories with sample below :

ID Name
1 News
2 Article
$catName = Categories::name(1);
echo $catName;

this will output News.

$catName = Categories::name(2);
echo $catName;

this will output Article.

See also:

getParent Method

Usage: echo Categories::getParent(int '$id');

Return: int

This is to get the Parent ID of a speicific Category ID.

example:

we have a list of categories with sample below :

ID Name Parent
1 News 0
2 Article 0
3 Latest 1
$parent = Categories::getParent(3);
echo $parent;

this will output 1.

See also:

Delete Method

Usage: Categories::delete(int '$id');

Return: bool

This method will delete a Category with a specific ID.

See also:

Type Method

Usage: Categories::type(int $id);

Return: string

Returns the type of a specific category (e.g., 'post', 'tag').

ID Method

Usage: Categories::id(string $name_or_slug);

Return: int

Returns the ID of a category based on its name or slug.

Exist Method

Usage: Categories::exist(int $id);

Return: bool

Checks if a category with the specified ID exists in the database.

Slug Method

Usage: Categories::slug(int $id);

Return: string

Returns the slug of a specific category.