Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to display all posts from multiple collections? #8

Open
salimbenfarhat opened this issue Jan 14, 2023 · 1 comment
Open

how to display all posts from multiple collections? #8

salimbenfarhat opened this issue Jan 14, 2023 · 1 comment

Comments

@salimbenfarhat
Copy link

Hello,
Please, how to display all posts from multiple collections?
Examples cookies and cakes collections. I want to display on one page, all collections posts.

@leebrian
Copy link

I'd like to see this in the example as well. Here's what I set up to include pages and all the collections (although I only wanted the pages with the specific page layout because I didn't want to search some other internal pages)...

<script>
window.store = {};
{% for page in site.pages %}
    {% if page.layout == "page" %}
        window.store["{{ page.url | slugify }}"]= {
            "title": "{{ page.title | xml_escape }}",
            "author": "{{ page.author | xml_escape }}",
            "category": "{{ page.category | xml_escape }}",
            "content": {{ page.content | strip_html | strip_newlines | jsonify }},
            "url": "{{ page.url | xml_escape }}"
        };
    {% endif %}
{% endfor %}

{% for collection in site.collections %}
    {% if site[collection.label].size > 0 %}
        {% for item in site[collection.label] %}
            window.store["{{ item.url | slugify }}"] = {
                "title": "{{ item.title | xml_escape }}",
                "author": "{{ item.author | xml_escape }}",
                "category": "{{ item.category | xml_escape }}",
                "content": {{ item.content | strip_html | strip_newlines | jsonify }},
                "url": "{{ item.url | xml_escape }}"
            };
        {% endfor %}
    {% endif %}
{% endfor %}
</script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants