I have a special page showing an archive of all blog posts and all articles for each tag. I created it with the following code (with the help of Copilot):
{% set posts = page.find('/blog').children.published.order('header.date', 'desc') %}
{% set post_count = 0 %}
{% for post in posts %}
{% set post_count = post_count + 1 %}
{% endfor %}
[Edited text...] **{{ post_count }} articles** [edited text].
<h2>Post per mese</h2>
{# Calcola l'anno e il mese correnti #}
{% set currentYear = "now"|date("Y")|int %}
{% set currentMonth = "now"|date("n")|int %}
{# Definisci la mappa dei mesi con abbreviazioni italiane #}
{% set monthNamesIt = {
1: 'gen', 2: 'feb', 3: 'mar', 4: 'apr', 5: 'mag', 6: 'giu',
7: 'lug', 8: 'ago', 9: 'set', 10: 'ott', 11: 'nov', 12: 'dic'
} %}
{% set monthNamesEn = {
1: 'jan', 2: 'feb', 3: 'mar', 4: 'apr', 5: 'may', 6: 'jun',
7: 'jul', 8: 'aug', 9: 'sep', 10: 'oct', 11: 'nov', 12: 'dec'
} %}
{# Calcola il numero di articoli per ciascun mese #}
{% set articles_per_month = {} %}
{% for post in page.find('/blog').children %}
{% set postYear = post.date|date("Y") %}
{% set postMonth = post.date|date("n") %}
{% set key = postYear ~ '-' ~ postMonth %}
{% if articles_per_month[key] is not defined %}
{% set articles_per_month = articles_per_month|merge({ (key): 1 }) %}
{% else %}
{% set articles_per_month = articles_per_month|merge({ (key): articles_per_month[key] + 1 }) %}
{% endif %}
{% endfor %}
{# Ciclo per ogni anno dall'anno corrente fino al 2016 (inizia da ottobre 2016) #}
{% for year in range(currentYear, 2016, -1) %}
<div class="year-header">
<h3>{{ year }}</h3>
</div>
<div class="month-links">
{# Definiamo il range dei mesi per ciascun anno: #}
{% if year == 2016 %}
{% set monthsRange = [10, 11, 12] %} {# Solo ottobre, novembre e dicembre per il 2016 #}
{% elseif year == currentYear %}
{% set monthsRange = range(1, currentMonth) %} {# Solo fino al mese corrente per l'anno attuale #}
{% else %}
{% set monthsRange = range(1, 12) %} {# Tutti i mesi per gli altri anni #}
{% endif %}
{# Itera sui mesi e non aggiunge "/" dopo l'ultimo mese #}
{% for month in monthsRange %}
{% set key = year ~ '-' ~ month %}
{% set article_count = articles_per_month[key] ?? 0 %}
{% if article_count > 0 %}
{% set url = "/blog/archives_month:" ~ monthNamesEn[month] ~ "_" ~ year %}
{% set text = monthNamesIt[month]|upper %}
<a href="{{ url }}">{{ text }}</a> <span class="label label-rounded">{{ article_count }}</span>{% if not loop.last %} / {% endif %}
{% else %}
{% set text = monthNamesIt[month]|upper %}
<span>{{ text }}</span>{% if not loop.last %} / {% endif %}
{% endif %}
{% endfor %}
</div>
{% endfor %}
<h2>Post per tag</h2>
{% set tags = {} %}
{# Filtra i post solo pubblicati e visibili #}
{% set posts = page.find('/blog').children.published.order('header.date', 'desc') %}
{# Raggruppa i post per tag, mantenendo l'ordine dei post (già discendente) #}
{% for post in posts %}
{% if post.taxonomy.tag is defined %}
{% for tag in post.taxonomy.tag %}
{% if tags[tag] is not defined %}
{% set tags = tags|merge({ (tag): [post] }) %}
{% else %}
{% set tags = tags|merge({ (tag): tags[tag]|merge([post]) }) %}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{# Itera sui tag in ordine alfabetico #}
<div class="accordion">
{% for tag in tags|keys|sort %}
<div class="accordion-item">
<input type="checkbox" id="accordion-{{ loop.index }}" hidden>
<label for="accordion-{{ loop.index }}" class="accordion-header">
<strong>{{ tag }}</strong> <span class="label label-rounded">{{ tags[tag]|length }}</span>
</label>
<div class="accordion-body">
<ul>
{# Elenco articoli per il tag corrente #}
{% for post in tags[tag] %}
<li><a href="{{ post.url }}">{{ post.title }}</a></li>
{% endfor %}
</ul>
</div>
</div>
{% endfor %}
</div>
You can see the page here: Archivio | Marco Cevoli (in Italian).
I don’t understand why the number of posts (the grey one) is displayed correctly, but if you click on the tag, the actual post titles displayed for the “newsletter” tag are 35 instead of 130…
If I debug with a simple loop, I can see the titles are indeed found.
I’ve looked almost everywhere and I can’t find any set limit…
What does this depend on? Grav code? The page.find function? The taxonomy plugin? The underlying PHP code? Some PHP variable on the server? A bug in the actual page twig?
TIA