I am completely new to Wix and Velo. I do not know any coding at all, but I was told the only way to add what I want to my website was to use code (the Editor and third party apps do not work for what I want).
Using the Wix Editor, I created dynamic list pages that lists multiple activities from an Activities Collection and dynamic items pages that shows detailed information for each activity.
This is the screenshot of the Activities Collection:
The Activity Title field is the primary field with the field key “title”.
This is the dynamic category list page that lists the activities by Module (i.e. Module 1, Module 2 etc. values shown in the Module field) for each activity.
This is the dynamic item page that shows the detailed content for each activity (like Activity Title, Activity Short Description etc).
On each activity’s page, under all the information, I want to add the option for users to add and view ratings and reviews for each activity on each activity dynamic item page, so that each page for each activity shows only the ratings and reviews submitted for that activity on that page and not show all the reviews submitted for all the activities on every activity page.
I found an old forum post https://www.wix.com/velo/forum/coding-with-velo/comments-reviews-on-dynamic-pages
If you scroll down on this page, there is a reply by Franz Coester on Sep 16, 2019 that includes some code on how to add ratings and reviews on dynamic pages.
Since I don’t really know much about coding, I don’t know how to edit this code to change the ids to refer to the items on my page, or the fields in my collections or anything…
I tried creating a Ratings collection like he says with a Reference back to my Activities collection (in his case his harbors collection/table), by adding a field in the collection, selecting the Field Type as Reference and selecting Activities collection under Referenced collection (please see screenshots below - the reference field is circled in red)
But I don’t know if I am doing this correctly or not, because in the screenshots from Franz Coester in the old forum post, the reference field is showing a database icon, while my reference field is showing some kind of link icon:
Frank Coester’s rating’s collection with reference field
My Ratings collection reference field:
This is part of the code he used load the rating to display the average and total number of ratings on the dynamic item page for each harbor:
$w.onReady( function () {
$w(‘#harbouritem’).onReady(() => {
harbouritem = $w(‘#harbouritem’).getCurrentItem()
loadrating()
})
});
exportfunction loadrating() {
let ratings;
wixData.query(‘Ratings’)
.eq(‘harbours’,harbouritem._id)
.find()
.then(result => {
ratings = result.items
let sumrating = 0
let countrating = 0
let rating = 0
countrating = result.totalCount
result.items.forEach(res => {
sumrating += res.rating
})
if (sumrating,countrating) {rating = sumrating/countrating}
$w(‘#harbourrating’).numRatings = countrating
if (rating > 0) {
$w(‘#harbourrating’).rating = rating
}
else {
$w(‘#harbourrating’).rating = undefined
}
})
}
I am having trouble understanding all the different things he is referring to in his code, like I don’t know what ‘#harbouritem’, ‘Ratings’,‘harbours’, harbouritem._id, ‘#harbourrating’ mean - are they the ids for elements on the page, the names of collections, fields from his collections or something else???
I also don’t know how to refer to a field in my collections in the code - like what the syntax is…
The # symbol seems to only work to refer to the ids of elements on the actual page, not a field in a collection.
Because I am not understanding what he is referring to in his code, I also don’t know what ids or code to substitute in his code so the code works with my collections, page elements etc.
So, I just need help from someone who can explain what each part of the code means and what I need to substitute to make it work for my website’s pages.
I greatly appreciate any help.
Thank you so much,
RT