Skip to content

getCategories(bool only_root, int items_per_page)

The getCategories method is used to get the CategoriesList object that represents a list of active root (main) categories. Method returns only active and translated categories.

Input parameters

only_root

int If parameter is set to true, method returns only root (main) categories, otherwise it returns all categories. Parameter is optional. Default value is false.

items_per_page

int Number of items in a page of internal paginator. Parameter is optional. Default value is 100.

Returned value

The CategoriesList object.

Example

source
{% set categories = ObjectApi.getCategories() %}

{% if categories is not empty %}
    <ul>
        {% for category in categories %}
            <li>{{ category.name }} - {% if category.isRoot %} main category {% else %} child category {% endif %}</li>
        {% endfor %}
    </ul>
{% endif %}
output
<ul>
    <li>Computers - main category</li>
    <li>PC - child category</li>
    <li>Notebooks - child category</li>
    <li>Tablets - main category</li>
    <li>Phones - main category</li>
</ul>
source
{% set categories = ObjectApi.getCategories(true) %}

{% if categories is not empty %}
    List of main categories only:
    <ul>
        {% for category in categories %}
            <li>{{ category.name }}</li>
        {% endfor %}
    </ul>
{% endif %}
output
List of main categories:
<ul>
    <li>Computers</li>
    <li>Tablets</li>
    <li>Phones</li>
</ul>