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

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Archive

Sorting posts (grouped by taxonomy)

Started by Muut Archive 9 years ago · 0 replies · 458 views
9 years ago

Hi!
I’m working on a directory of design pieces in a collection. The pages are structured showing first a list of designers (using taxonomies and taxonomylist-plugin). After clicking on the designer’s name, a list with correspondent design pieces appears (posts styled as dropdown accordions).

Here’s the structure:

TXT
_Designer A
_Designer B
___Item 1 (by Artist B)
___Item 2 (by Artist B)
___Item 3 (by Artist C)
_Designer C

I managed to sort the designers using ksort, however I have no idea how to achieve this for the design items (posts). Please find below the code I’m using:

TWIG
<li>
    {% set tags = taxonomy.taxonomy['designer']|ksort %}
    {% for tag, items in tags %}
        <button class="accordion">
            <h1>{{ tag }}</h1>
        </button>

        <div class="panel">
            {% for path, slug in items %} 
            {% set post = grav['pages'].get(path) %}
            {% if post.title != null %}
                <button class="accordion sublevel">
                    <h1>{{ post.title }}</h1>
                </button>

            <div class="panel sublevel">
                <p>{{ post.content }}</p>
            </div>
            {% endif %}
            {% endfor %}
        </div>         
</li>

Does anyone have an idea on how to solve this issue? I’m unfortunately not really a coding pro. Thanks in advance!
Cheers

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1282 9 years ago
Archive · by Muut Archive, 9 years ago
2 889 9 years ago
Archive · by Muut Archive, 9 years ago
2 4019 9 years ago
Archive · by Muut Archive, 9 years ago
1 2894 9 years ago
Archive · by Muut Archive, 9 years ago
3 1078 9 years ago