diff --git a/layouts/partials/widgets/pages.html b/layouts/partials/widgets/pages.html
index 7a32df79..71b6a2e1 100644
--- a/layouts/partials/widgets/pages.html
+++ b/layouts/partials/widgets/pages.html
@@ -40,6 +40,8 @@
{{ $query = where $query "Date" "<" now }}
{{ end }}
+{{ $count := len $query }}
+
{{/* Sort */}}
{{ $sort_by := "Date" }}
{{ $query = sort $query $sort_by $items_sort }}
@@ -51,8 +53,6 @@
{{ $query = first $items_count $query }}
{{ end }}
-{{ $count := len $query }}
-
{{/* Localisation */}}
{{ $i18n := "" }}
{{ if eq $items_type "post" }}