Using one collection to show two galleries on a page?

Hi all, I am having trouble filtering my collection to show in two galleries. Do I need to create another collection? If I do that, will it still work with dynamic pages? Having a hard time wrapping my head around this. Some screenshots attached… On the live site, it is just showing my ‘custom home’ filter even though the second dataset is filtered to show ‘other’ … any ideas?

Hi @creative

Great question! I’ll check in with our resident Product Expert and see what he may be able to uncover 🕵🏽‍♀️

Hi there,

You are correct in that you will need a second collection to separate what is being displayed.

It is not possible to choose what images are to be displayed to certain elements.

This method will still work with your Dynamic Pages. If you run into any issues with your Dynamic Pages please reach out to our Customer Care Team so that they can take a look directly into your site. I hope this helps!

Hey there,

Actually, yes, you can display two different galleries on your dynamic dataset, you’ll either need two datasets (which can slow down the page), or populate the galleries with code (if you’re into that).

Using a query, get the items from the database, filter them then assign them to the items property of the gallery

import wixData from 'wix-data';

$w.onReady(() => {
    getItems().then((result) => {
        $w('#customGallery').items = result.custom;
        $w('#gallery').items = result.other;
    })
})

function getItems() {
    return wixData.query('collection').find().then((x) => {
        const items = x.items;
        const custom = items.filter(items => items.customHome === true);
        const other = items.filter(items => items.customHome !== true);
    
        return {
            custom: custom,
            other: other
        }
    })
}

Hi @ahmadnasriya ,

Thank you for your response. This is the ideal solution as the site is for a client so one place to input the info will eliminate steps.

I apologize, I am trying to incorporate code into my sites but I am still very new. Could you explain how to assign the items property?

Thanks,
Gabrielle - Code Newbie

@creative As fot the errors, I had a typo in my code (I fixed it), as for the items properties, you need change the IDs of the galleries, edit the field name, the collection name and basically adapt the code to your needs.