List only those months that have entries
{% set date = (date()).modify('first day of january 00:00:00') %}
{% for month in 1..12 %}
    {% set endOfMonth = clone(date).modify('last day of this month') %}
        {% set exists= craft.entries
            .postDate(['and', '&gt;=' ~ date.format('-.m-d H:i:s'), '&lt;=' ~ endOfMonth.format('Y-m-d H:i:s') ])
            .exists()
        %}

    {% do date.modify('first day of next month') %}
{% endfor %}


loop all months and check if there are entries in this month or not