Skip to content

Instantly share code, notes, and snippets.

@jacksleight
Last active October 27, 2022 15:16
Show Gist options
  • Save jacksleight/dd8e3b9a17d82a12ab0a3982770c1c3a to your computer and use it in GitHub Desktop.
Save jacksleight/dd8e3b9a17d82a12ab0a3982770c1c3a to your computer and use it in GitHub Desktop.
Add entry count to taxonomy term listing
<?php
namespace App\Providers;
use App\Taxonomies\LocalizedTerm;
use Illuminate\Support\ServiceProvider;
use Statamic\Taxonomies\LocalizedTerm as StatamicLocalizedTerm;
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
$this->app->bind(StatamicLocalizedTerm::class, LocalizedTerm::class);
}
}
title: Category
sections:
main:
display: Main
fields:
-
handle: entries_count
field:
type: hidden
display: Entries
listable: true
<?php
namespace App\Taxonomies;
use Statamic\Taxonomies\LocalizedTerm as StatamicLocalizedTerm;
class LocalizedTerm extends StatamicLocalizedTerm
{
public function value($key)
{
if ($key === 'entries_count') {
return $this->entriesCount();
}
return parent::value($key);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment