Question:
How can I create/divide a dataset so that on one part of the page I insert the first 8 posts of my CMS and in another part the rest (starting on number 9)?
Product:
Wix Studio Editor
What are you trying to achieve:
As the blog posts list is a bit limited in terms of styling, I have created (using a repeater and conencting it to a CMS dataset) my own design. The thing is that on my blog I have 272 posts and I want to show the first 8 posts at the begining of the page, then two different sections and finally the rest of the posts (all of them, probably charging them with a LoadMore Button). The problem here is that I don’t know how to create a new dataset which starts at number 9 (and not including the 8 previous posts).
What have you already tried:
I’ve tried conecting the same dataset to two different repeaters & creating two diferent datasets but both things repeat the same posts, without starting from number 9.
Additional information:
It’s important to know that the blog CMS is not editable, for being a part of the WIX blog pluging!
Thank you for responding, but this is not how I end up making it. I ended up creating two different datasets and configuring the second one via Javascript, where we remove the first 9 posts.
$w.onReady(function () {
const collectionName = "Blog/Posts"; //THIS IS THE NAME FOR THE BLOG POSTS COLLECTION
const limit = 100; //THIS NEEDS TO STAY LIKE THIS BECAUSE WIX HAS A LIMIT OF 100 REQUESTS
let items = [];
function fetchAllItems(skip = 0) {
return wixData.query(collectionName)
.limit(limit)
.skip(skip)
.find()
.then((result) => {
items = items.concat(result.items);
if (result.hasNext()) {
return fetchAllItems(skip + limit);
}
return items;
});
}
let dataset = $w("#dataset10"); //HERE IS THE NAME OF THE SECOND DATASET
dataset.onReady(() => {
fetchAllItems()
.then((allItems) => {
// Get IDs of the first 8 items
const idsToExclude = allItems.slice(0, 9).map(item => item._id);
console.log("IDs to exclude:", idsToExclude);
// Apply a filter to exclude the first 8 items
const filter = wixData.filter().not(
wixData.filter().hasSome("_id", idsToExclude)
);
dataset.setFilter(filter)
.then(() => {
return dataset.refresh();
})
.catch((error) => {
console.error("Error applying filter or refreshing dataset:", error);
});
})
.catch((error) => {
console.error("Error:", error);
});
});
});```