PHPackages                             pdaleramirez/category-tree - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. pdaleramirez/category-tree

ActiveCraft-plugin[Utility &amp; Helpers](/categories/utility)

pdaleramirez/category-tree
==========================

Builds a category tree structure for your menu and links.

1.0.6(6y ago)76262MITPHP

Since Apr 22Pushed 6y ago3 watchersCompare

[ Source](https://github.com/pdaleramirez/category-tree)[ Packagist](https://packagist.org/packages/pdaleramirez/category-tree)[ RSS](/packages/pdaleramirez-category-tree/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (6)Used By (0)

Category Tree plugin for Craft CMS 3.x
======================================

[](#category-tree-plugin-for-craft-cms-3x)

Builds a Category tree structure for your menu and links.

Installation
------------

[](#installation)

To install Category Tree, follow these steps:

1. Download &amp; unzip the file and place the `category-tree` directory into your `craft/plugins` directory
2. -OR- do a `git clone https://github.com/pdaleramirez/category-tree.git` directly into your `craft/plugins` folder.
    You can then update it with `git pull`
3. -OR- install with Composer via `composer require pdaleramirez/category-tree`
4. Install plugin in the Craft Control Panel under Settings &gt; Plugins
5. The plugin folder should be named `category-tree` for Craft to see it. GitHub recently started appending `-master` (the branch name) to the name of the folder for zip file downloads.

Category Tree works on Craft 3.x.

Category Tree
-------------

[](#category-tree)

You can use this plugin to fetch craft recursive categories tree in your control panel.

Fetch Category Tree
-------------------

[](#fetch-category-tree)

Use `{{ craft.categorytree.getTree(1) }}` in you template to you fetch the category tree structure from your category control panel with "groupId" as your first parameter.

### Example output:

[](#example-output)

```
[
    0 => [
        'id' => '14'
        'parentId' => 0
        'title' => 'Dropdown 1'
        'model' => 'craft\\elements\\Category'
        'children' => [
            0 => [
                'id' => '15'
                'parentId' => '14'
                'title' => 'Dropdown 1.1'
                'model' => 'craft\\elements\\Category'
                'children' => [
                    0 => [
                        'id' => '22'
                        'parentId' => '15'
                        'title' => 'Dropdown 1.1.1'
                        'model' => 'craft\\elements\\Category'
                    ]
                    1 => [
                        'id' => '23'
                        'parentId' => '15'
                        'title' => 'Dropdown 1.1.2'
                        'model' => 'craft\\elements\\Category'
                    ]
                    2 => [
                        'id' => '24'
                        'parentId' => '15'
                        'title' => 'Dropdown 1.1.3'
                        'model' => 'craft\\elements\\Category'
                    ]
                ]
            ]
            1 => [
                'id' => '13'
                'parentId' => '14'
                'title' => 'Dropdown 1.2'
                'model' => 'craft\\elements\\Category'
            ]
            2 => [
                'id' => '11'
                'parentId' => '14'
                'title' => 'Dropdown 1.3'
                'model' => 'craft\\elements\\Category'
            ]
        ]
    ]
    1 => [
        'id' => '17'
        'parentId' => 0
        'title' => 'Dropdown 2'
        'model' => 'craft\\elements\\Category'
        'children' => [
            0 => [
                'id' => '25'
                'parentId' => '17'
                'title' => 'Dropdown 2.1'
                'model' => 'craft\\elements\\Category'
                'children' => [
                    0 => [
                        'id' => '27'
                        'parentId' => '25'
                        'title' => 'Dropdown 2.1.1'
                        'model' => 'craft\\elements\\Category'
                    ]
                    1 => [
                        'id' => '30'
                        'parentId' => '25'
                        'title' => 'Dropdown 2.1.2'
                        'model' => 'craft\\elements\\Category'
                    ]
                ]
            ]
            1 => [
                'id' => '28'
                'parentId' => '17'
                'title' => 'Dropdown 2.2'
                'model' => 'craft\\elements\\Category'
            ]
            2 => [
                'id' => '26'
                'parentId' => '17'
                'title' => 'Dropdown 2.3'
                'model' => 'craft\\elements\\Category'
            ]
        ]
    ]
    2 => [
        'id' => '12'
        'parentId' => 0
        'title' => 'Dropdown 3'
        'model' => 'craft\\elements\\Category'
        'children' => [
            0 => [
                'id' => '16'
                'parentId' => '12'
                'title' => 'Dropdown 3.1'
                'model' => 'craft\\elements\\Category'
            ]
            1 => [
                'id' => '29'
                'parentId' => '12'
                'title' => 'Dropdown 3.2'
                'model' => 'craft\\elements\\Category'
            ]
        ]
    ]
]
```

The model index returns the Category object.

### Example Implementation

[](#example-implementation)

```
{% set categories = craft.categorytree.getTree() %}

{% for category in categories %}

  {{ category.model.slug }}

  {% if category.children is defined %}

    {% for category in category.children %}
      {{ category.model.slug }}
    {% endfor %}

  {% endif %}

{% endfor %}

```

Display Category List
---------------------

[](#display-category-list)

Use the function below to display html category list.

First parameter is the base url link.

Second parameter is the attribute key of the category model and this will get display at the end of your base url.

Third parameter is the css class of the "ul" html element.

```
{{ craft.categorytree.getList(1,{'base': '/category/',
                                  'attribute': 'slug',
                                  'class': 'category-tree'
                                  }) }}
```

### HTML Output:

[](#html-output)

```

      Dropdown 1

            Dropdown 1.1

               Dropdown 1.1.1
               Dropdown 1.1.2
               Dropdown 1.1.3

         Dropdown 1.2
         Dropdown 1.3

      Dropdown 2

            Dropdown 2.1

               Dropdown 2.1.1
               Dropdown 2.1.2

         Dropdown 2.2
         Dropdown 2.3

      Dropdown 3

         Dropdown 3.1
         Dropdown 3.2

```

Display JavaScript dropdown menu
--------------------------------

[](#display-javascript-dropdown-menu)

```
{{ craft.categorytree.getMenu(1,{'base': '/category/',
                                  'attribute': 'slug',
                                  'class': 'category-tree'
                                  }) }}

```

Brought to you by [Precious Dale Ramirez](https://github.com/pdaleramirez)

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 77.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~210 days

Total

5

Last Release

2512d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/80ecfeba39735012c4d9816b834a200b55b09e5338357329edb98ecbb2bfe183?d=identicon)[pdaleramirez](/maintainers/pdaleramirez)

---

Top Contributors

[![pdaleramirez](https://avatars.githubusercontent.com/u/4172750?v=4)](https://github.com/pdaleramirez "pdaleramirez (7 commits)")[![brandonkelly](https://avatars.githubusercontent.com/u/47792?v=4)](https://github.com/brandonkelly "brandonkelly (2 commits)")

---

Tags

cmsCraftcraftcmscraft-plugincategory tree

### Embed Badge

![Health badge](/badges/pdaleramirez-category-tree/health.svg)

```
[![Health](https://phpackages.com/badges/pdaleramirez-category-tree/health.svg)](https://phpackages.com/packages/pdaleramirez-category-tree)
```

###  Alternatives

[verbb/formie

The most user-friendly forms plugin for Craft.

100387.6k58](/packages/verbb-formie)[nystudio107/craft-seomatic

SEOmatic facilitates modern SEO best practices &amp; implementation for Craft CMS 5. It is a turnkey SEO system that is comprehensive, powerful, and flexible.

1741.5M52](/packages/nystudio107-craft-seomatic)[verbb/navigation

Create navigation menus for your site.

92698.4k18](/packages/verbb-navigation)[verbb/field-manager

Manage your fields and field groups with ease.

195612.2k10](/packages/verbb-field-manager)[verbb/workflow

Enforce multi-step review processes for creating entries.

138123.0k1](/packages/verbb-workflow)[verbb/comments

Add comments to your site.

13753.7k](/packages/verbb-comments)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
