Skip to main content

Category tree

Category tree loop, to get a category tree from a given category to a given depth.
{loop type="category_tree" name="the-loop-name" [argument="value"], [...]}

Arguments

ArgumentDescriptionDefaultExample
category *A single category id.category="2"
depthThe max depthdepth="5"
excludeA single or a list of category ids to exclude for result.exclude="5,72"
need_count_childA boolean which indicates whether the number of children in each category should be taken into account
orderA list of values
Expected values
positionorder="random"
visibleWhatever we consider hidden category or not.true

Plus the global arguments

Outputs

VariableValue
$CHILD_COUNTThe number of direct children of a category in the tree
$IDthe category id
$LEVELThe depth of the category in the tree
$PARENTthe parent category
$PREV_LEVELThe depth of the direct parent category in the tree.
$TITLEthe category title
$URLthe category URL
$VISIBLEwhatever the category is visible or not

Plus the global outputs

Examples

I want to display a select list with all visible categories.

<select name="category">
{loop name="categories-tree" type="category-tree" category="0"}
<option value="{$ID}">{"-"|str_repeat:$LEVEL} {$TITLE} {if $CHILD_COUNT != 0}({$CHILD_COUNT}){/if}</option>
{/loop}
</select>

Order possible values

Arguments

Ascending valueDescending valueSorted fields
alphaalpha_reversesort by column
idid_reverseid
positionposition_reverseposition