Question:
I am showing 3 posts per category on a repeater and I have a “Show all” button that i want to show all posts in that category. (the categories change depending on different buttons)
Product:
Wix Editor
What are you trying to achieve:
My current code:
// load category on btn press
function LoadRelatedCategoryPosts(categoryId) {
return wixData.query('Blog/Posts')
.hasSome('categories', categoryId)
.limit(3)
.find()
.then(results => {
$w('#repeaterPosts').data = results.items;
})
}
// activate on btn presses
function catButtons(btnCat, categoryId) {
$w(btnCat).onClick((event) => {
LoadRelatedCategoryPosts(categoryId);
})
$w('#btnShowAll').onClick((event) => {
// NEED CODE HERE
})
}
What have you already tried:
I’ve tried adding .limit(100) to an other wixData.query('Blog/Posts), but that not only shows all blog posts, it glitches and functions oddly.
Additional information:
Currently, your LoadRelatedCategoryPosts
function is limiting the results to 3 posts.
To show all posts, you can create a new function that doesn’t limit the results. This function will be similar to LoadRelatedCategoryPosts
, but without the .limit(3)
line.
Then, you can call this new function when the “Show all” button is clicked.
// load all category posts on "Show all" button press
function LoadAllCategoryPosts(categoryId) {
return wixData.query('Blog/Posts')
.hasSome('categories', categoryId)
.find()
.then(results => {
$w('#repeaterPosts').data = results.items;
})
}
// activate on btn presses
function catButtons(btnCat, categoryId) {
$w(btnCat).onClick((event) => {
LoadRelatedCategoryPosts(categoryId);
})
$w('#btnShowAll').onClick((event) => {
LoadAllCategoryPosts(categoryId);
})
}
Thanks Dan_Surh,
But hmm, SO it’s somewhat works but glitches a lot.
The only category that has more than 3 posts atm is Featured. when i click show more posts, the posts move to showing all the featured posts (like it is supposed to), to showing all posts (not just a the featured post), and finally to the Articles posts.
Suggestions why this is acting like this? Solutions?
I havn’t had a change to test the above code. Will see if I can get it working correctly.
Wow, so nice! I’ve been plugging away, I’m obviously new at wix velo code. Much appreciated