Skip to content
Grav 2.0 is officially stable. Read the announcement →
Plugins

Language Filtered Pagination Plugin

plugins theme

Started by Ceyhun Enki Aksan 6 years ago · 0 replies · 553 views
6 years ago

Hello Team,

I am using pagination and langswitcher plugins. There is no problem when I list the posts (90 posts, limit: 10) in the predefined language (EN), 9 different pages (pagination|length) are created (page:1...to page:9) by plugin.

However, when I try to view the posts in other language (FR which has 4 posts), I still see 9 pagination pages. How can I filter paginate.number by language?

TWIG
{% set options = { items: {'@self.children':''} } %}
{% set pagination = pagination|default(page.collection(options).params.pagination) %}
{% set language = grav.language.getLanguage %}
{% set base_url = base_url|default(page.url) %}

{% if pagination|length > 1 %}
    <ul class="pagination">
        {% if pagination.hasPrev %}
            {% set url =  (base_url ~ pagination.params ~ pagination.prevUrl)|replace({'//':'/'}) %}
            <li><a rel="prev" href="{{ url }}">&laquo;</a></li>
        {% else %}
            <li><span>&laquo;</span></li>
        {% endif %}

        {% for paginate in pagination %}
            {% if paginate.isCurrent %}
                <li><span class="active">{{ paginate.number }}</span></li>
            {% elseif paginate.isInDelta %}
                {% set url = (base_url ~ pagination.params ~ paginate.url)|replace({'//':'/'}) %}
                <li><a href="{{ url }}">{{ paginate.number }}</a></li>
            {% elseif paginate.isDeltaBorder %}
                <li class="gap"><span>&hellip;</span></li>
            {% endif %}
        {% endfor %}
        {% if pagination.hasNext %}
            {% set url = (base_url ~ pagination.params ~ pagination.nextUrl)|replace({'//':'/'}) %}
            <li><a rel="next" href="{{ url }}">&raquo;</a></li>
        {% else %}
            <li><span>&raquo;</span></li>
        {% endif %}
    </ul>
{% endif %}

Thank you.

Suggested topics

Topic Participants Replies Views Activity
Plugins · by Rene, 1 week ago
2 83 1 week ago
Plugins · by Xavier, 4 weeks ago
2 85 4 weeks ago
Plugins · by Luka Prinčič, 7 years ago
3 1211 1 month ago
Plugins · by Sebastian van de Meer, 1 month ago
1 78 1 month ago
Plugins · by PIERROT Alain, 2 months ago
3 105 2 months ago