diff --git a/admin.php b/admin.php index 9278fab2..a44443d6 100644 --- a/admin.php +++ b/admin.php @@ -330,6 +330,8 @@ class AdminPlugin extends Plugin // make sure page is not frozen! unset($this->grav['page']); + $this->admin->pagesCount(); + // Replace page service with admin. $this->grav['page'] = function () use ($self) { $page = new Page; diff --git a/classes/admin.php b/classes/admin.php index 26720225..520de6e4 100644 --- a/classes/admin.php +++ b/classes/admin.php @@ -75,6 +75,11 @@ class Admin */ protected $gpm; + /** + * @var int + */ + protected $pages_count; + /** * Constructor. * @@ -404,9 +409,13 @@ class Admin * * @return array */ - public function countPages() + public function pagesCount() { - return count($this->grav['pages']->all()); + if (!$this->pages_count) { + $this->pages_count = count($this->grav['pages']->all()); + } + + return $this->pages_count; } /** diff --git a/themes/grav/templates/partials/nav.html.twig b/themes/grav/templates/partials/nav.html.twig index f93d9a08..d84c1cd3 100644 --- a/themes/grav/templates/partials/nav.html.twig +++ b/themes/grav/templates/partials/nav.html.twig @@ -34,7 +34,7 @@ {{ "PLUGIN_ADMIN.PAGES"|tu }} - {{ admin.countPages }} + {{ admin.pagesCount }}