# Categories and Tags

Source: https://kart.bnomei.com/docs/content/categories-and-tags
Updated: 2025-08-08T14:02:19+00:00
Summary: Learn how to use the Kirby Kart plugin for categories, tags, related products, URL-param filtering, and performance-boosting caching in your Kirby CMS store.

## Categories

Code (php):  
```
<?php foreach (kart()->categories()->sortBy('count', 'desc') as $c) {
    /** @var \Bnomei\Kart\Category $c */
    ?>
    <a class="<?php e($c->isActive(), 'is-active') ?>" 
       href="<?= $c->urlWithParams() ?>"><?= $c ?></a>
<?php } ?>
```

  
- `$category->count()`
- `$category->id()`
- `$category->isActive()`
- `$category->text()`
- `$category->url()`
- `$category->urlWithParams()`

Code (php):  
```
<?php 
// productsWithCategory(string|array $categories, bool $any = true)
foreach (kart()->productsWithCategory($categories) as $product) {
    /** @var ProductPage $product */
    ?>
    <a href="<?= product->url() ?>"><?= product->title() ?></a>
<?php } ?>
```

  
## Tags

Code (php):  
```
<?php foreach (kart()->tags()->sortBy('count', 'desc') as $t) {
    /** @var \Bnomei\Kart\Tag $t */
    ?>
    <a class="<?php e($t->isActive(), 'is-active') ?>" 
       href="<?= $t->urlWithParams() ?>"><?= $t ?></a>
<?php } ?>
```

  
- `$tag->count()`
- `$tag->id()`
- `$tag->isActive()`
- `$tag->text()`
- `$tag->url()`
- `$tag->urlWithParams()`

Code (php):  
```
<?php 
// productsWithTag(string|array $tags, bool $any = true)
foreach (kart()-> productsWithTag($tags) as $product) {
    /** @var ProductPage $product */
    ?>
    <a href="<?= product->url() ?>"><?= product->title() ?></a>
<?php } ?>
```

  
## Related products

Code (php):  
```
<?php foreach (kart()->productsRelated($product)->not($product) as $related) {
    /** @var ProductPage $related */ ?>
    <a href="<?= $related->url() ?>"><?= $related->title() ?></a>
<?php } ?>
```

  
## Products by URL params

Path: http://localhost:8000/products/category:evil/tags:heavy,medium  
Code (php):  
```
<?php foreach (kart()->productsByParams() as $product) {
    /** @var ProductPage $product */ ?>
    <a href="<?= $product->url() ?>"><?= $product->title() ?></a>
<?php } ?>
```

  
## Performance

The Kirby Kart plugin will store the matching products for each combination of categories and tags in caches to improve the lookup performance. These caches will be flushed when any product gets updated via the Panel.