Comments / Reviews on Dynamic Pages

To anyone who is stuck on adding comments or reviews on dynamic pages check this out
https://sidiraskon.wixsite.com/dynamicpage-comments

I’ve added the following features:

  1. Create comments on dynamic pages that auto populate on repeater and register information on database. Then show the correct comments on each dynamic page.

2)When new comment is added, it shows on the list immediately

  1. Total number of comments for the specific page calculation

  2. Load more button that shows only if there are more than 5 comments. When clicked it loads five more comments

1 Like

Great solution!!!
This is exactly what I’m looking for. I have solved the part where the user posts a comment, did that in a Lightbox.
But now I want to show the existing comments on the dynamic page. Can you give me some guidance how you did that?

Solved the problem, didn’t know about repeaters…

HI can u give some guidance on how to show comments in the correct dynamic page? ive been struggling with this for a week now ;(

OK, so I will try to explain how I did it
My website is Skippertools.app, you can have a look there under harbour guide.

What I do there is showing harbors on the harbor guide page, the harbors are stored in the database. By clicking on a harbor the details are shown on a dynamic page. On this page one can rate and comment on the harbor.
For the comments I created a table “Ratings”. The table “ratings” contains a reference field to the table “harbours”


Now, on the harbour guide page I show a list of harbors like a table. However I didn’t use a table, since it’s useless in terms of design. Therefore I used a repeater.


So this is how you add a repeater, further down are the tables. Choose any repeater and work on the design as desired.
Of course you have to add a dataset (in my case harbors) and connect it to the repeater and the fields inside the repeater.


Next to the dynamic page where the details of the harbor is shown. I assume it is clear how to do that.
Below the harbor info I show ratings and comments.

First of all I show the average rating and the total number of ratings. I already had the dataset for the harbor on the page, next I added a dataset for the ratings. And then of course a rating display.
In the code I load the rating as follows:

$w.onReady(function () {
    $w('#harbouritem').onReady(() => {
        harbouritem = $w('#harbouritem').getCurrentItem()
        loadrating()
    })
});
export function 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
        }
    })
}

Note: you will get a warning by setting the rating to undefined, but according to the documentation this is correct and it works accordingly.

Add a comment
To allow a visitor to add a comment, I chose a Lightbox as solution.
Clicking on the + Symbol calls the Lightbox and enables the user to enter the comment and rating.
So add a Lightbox which will finally look like this.


Now, to connect the comment with the harbor, the Lightbox needs to now the harbor. Therefore, my + Symbol is not directly linked to the Lightbox, but I have to do that in the code and communicate the harbor to the Lightbox.

export function addrating_click(event) { //addrating is the + symbol
    wixWindow.openLightbox('Bewertung', { // Name of Lightbox
        'harbouritem' : harbouritem
    })
    .then(() => {
        $w('#harbourratings').refresh()
    })
}

And in the Lightbox I receive the harbouritem like this

$w.onReady(function () {
 let received = wixWindow.lightbox.getContext();
    harbourrecord = received.harbouritem
})

Display the comments on the Dynamic Page

First you add a repeater for the Comments on the Dynamic Page. This repeater is connected to the ratings table. The fields inside the repeater can easily be connected to the respective table fields.


And now it works, since I already did the code for the query of ratings before.

I hope this helps. I know, I read some posts with explanations myself and was clueless afterwards. So anybody needs more help, just send a reply.

6 Likes

@franzcoester Thank you for the valuable info, really appreciate all the efforts in putting in explaining it step by step, i’ll give it a shot tomorrow and see how it goes. Gracias!

@adelinekiersten Did this work ?

Could you help me out setting ratings on dynamic pages?

Old post reappearing, closed.
Use the search function in the forum to find previous posts on this.
Add a new forum post if help still needed.