Jump to content
quickjeff

Average Rating from Comments Field

Recommended Posts

If you are using this module 

 

you can simply do 

$page->ratings->average;

 

Share this post


Link to post
Share on other sites

Unfortunately I am not. I am using the comment module from core modules with the ratings enabled. 

Share this post


Link to post
Share on other sites

Hello,

here is example from one of my projects and don't know if that can help you.

comments-foto-2.png.ef4f2c222db68157819c5942fdd2ac55.png

That example show AVG of 4.6, and below is copy/paste how I get that.

I believe that only what you need is to set "use stars", and this call:

$page->comments->renderStars(true, array('schema'=>'microdata','partials'=>true));

Or more details, where I use that:

<?php if($page->comments->count):?>
<div class="star-rating">
   <div class="rating-counter">
	   <a href="#listing-reviews">
	   <?php echo $page->comments->renderStars(true, array('schema'=>'microdata','partials'=>true));?>
	   </a>
   </div>
</div>
<?php endif;?>

If that is interesting, here is and Comments configuration to use Font Awesome icons.

CommentStars::setDefault('star', '<i class="fa fa-star"></i>'); //<= star item using fontawesome icon

Regards.

  • Like 4
  • Thanks 2

Share this post


Link to post
Share on other sites

Thank you! This is exactly what I was looking for. I’ll modify to work how I need it to work but thank you so much!!!!

  • Like 1

Share this post


Link to post
Share on other sites

Hello @OLSA Could you please explain where should I put the 

CommentStars::setDefault('star', '<i class="fa fa-star"></i>'); //<= star item using fontawesome icon

as this is my first time needing to replace the default stars with some FA icons and it would be a great addition to my learning curve 🙂 I see the same info in the comments field details tab, however am not sure how to insert it properly to have the stars changed to else.

Share this post


Link to post
Share on other sites

Hello @MilenKo

you need to do that somewhere before Comments module render methods calls ( renderStars() for page rating, and render() for user reviews ).

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Rhen GWL
      I'm trying to install comments on two of my clients' websites. In both cases, I'm able to display the comment submission form, but the form submissions are not being saved or display. Once I click the submit button, I'm directed to the homepage where #CommentForm is appended to the end of the URL. I have looked through countless forums and Google searches, but I can't find any advice that has fixed this issue. I have followed the instructions from https://processwire.com/docs/modules/guides/comments/ exactly as described, and I'm getting no where.
      Like I said, this is set up on two different websites and I'm seeing the same issues with both. I assume it's some issue with connecting with a database, but I don't see anything in the instructions on PW's website that says I need to do anything there.
    • By eschoonen
      I'm working on the threaded comments on my website and for this I need to include the comments.js
      When I do this it keeps on giving me the "Uncaught ReferenceRrror: jQuery is not defined". Whatever I do it keeps giving me this error message.
      It's the last javascript file that I load in. So how do I fix it?
    • By quickjeff
      Hi Guys,
      I am running a page template that contains a filter form that allows users to display results based on number of  comments. 
      Here is what I am thinking about doing: 
      -add new field called total_comments 
      -somehow populate this field every time a new comment is added or removed by admin with count($page->comments)
      -use form filter to display results that the selector form has found.
      Example: $selector = “total_comments>=$q”; 
       
      My question to everyone: Is this a good approach? If so how do I get another field to update based on the comment module adding or removing a comment? 
    • By albertax
      Hi, I am wondering if someone can help me out with getting the count of the comments of a page? 
      I am using Ryan's comments module as a reviews system for my site and would like to display the count of the comments per page, as below 
       

       
      The shops part that you see above is something similar to this 
      <?php $set_page = $page->title; $count = $pages->count("template=prices, title=$set_page"); echo $count; ?>  
    • By mtn
      The "Comments" core module has been activated locally with its four associated parts, including an Akismet API key, and has been rendered as per instruction via http://processwire.com/api/fieldtypes/comments/.  Testing the comment form continues to render errors after this manner in the 3.0.96 version.
      Error: Exception: Invalid email address (processwire@localhost:8888) (in ... /wire/core/WireMail.php line 130)  
      After an exhaustive attempt on my part to overcome this error (with limited knowledge), I considered that maybe a corrupt file might be the cause.  However, after updating from 3.0.62 to 3.0.96, the same error persists.  Below is the particular section/line of code mentioned.
      /** * Sanitize an email address or throw WireException if invalid * * @param string $email * @return string * @throws WireException * */ protected function sanitizeEmail($email) { $email = strtolower(trim($email)); $clean = $this->wire('sanitizer')->email($email); if($email != $clean) { $clean = $this->wire('sanitizer')->entities($email); throw new WireException("Invalid email address ($clean)"); //<--- this is the line } return $clean; }  
      Inasmuch as this is the final element that needs to be addressed for this particular site, your assistance in helping me understand the issue and the remedy regarding this matter would be greatly appreciated.  Good day!
       
×
×
  • Create New...