This is the community forum. For a developer response use the Client Area.
Follow us on Facebook, Twitter and YouTube!

Different testimonials on page refresh?
#1

I'm using commentics for my Testimonial page and was wondering if it's built in some where or if it can be added to where on a page refresh it randomly will show different user testimonials.
Reply
#2

Hi,

That's an interesting request. I can see how it would be useful.

In comments/includes/template/comments.php, replace this (line 358):

PHP Code:
<?php 
if ($settings->newest_first == "1") {
$sort = "is_sticky DESC, dated DESC"; //newest
} else {
$sort = "is_sticky DESC, dated ASC"; //oldest
}

With this:

PHP Code:
<?php 
if ($settings->newest_first == "1") {
$sort = "is_sticky DESC, RAND()"; //newest
} else {
$sort = "is_sticky DESC, RAND()"; //oldest
}

Have you completed the interview?
Reply
#3

Hi Steven, I have a follow up question to this thread.I have a website where patients can leave reviews using the commentics script which has been working very well. I now want to add the functionality where I could have random reviews shown on other pages in the website (new random review on every page refresh).

From your code above, it seems like editing the comments.php in addition to changing the layout so that only 1 comment is shown would do the trick but that would break my review page where all the reviews are listed. Additionally, also I think there would always be a form or link to the input form on every testimonial.

Is there a way to have one page where users can leave reviews and view all the past reviews and have an additional testimonial functionality on other pages?

Im using version 2.2.
Reply
#4

Hi apoonawa,

I don't normally provide support for Commentics v2.2 as it's almost 3 years old. If you upgrade to the latest version then I think you could use the Extractor add-on for this. You would need to add a new function in extractor.php which I have provided below. It will get one random comment on each page refresh (you'll need to style the output from it).

PHP Code:
<?php 
public function randomComment() {
$html = '';

$comments = mysqli_query($this->getLink(), "SELECT * FROM `" . $this->getPrefix() . "comments` WHERE `is_approved` = '1' ORDER BY RAND() LIMIT 1");

while (
$comment = mysqli_fetch_array($comments)) {
$page_query = mysqli_query($this->getLink(), "SELECT * FROM `" . $this->getPrefix() . "pages` WHERE `id` = '" . $comment["page_id"] . "'");

$page = mysqli_fetch_assoc($page_query);

$html .= $comment["name"] . "<br>";
$html .= "<a href='" . $page["url"] . "?cmtx_perm=" . $comment["id"] . "#cmtx_perm_" . $comment["id"] . "'>" . $page["reference"] . "</a>" . "<br>";
$html .= date("g:ia (jS-M)", strtotime($comment["dated"]));
$html .= $comment["comment"];
}

return
$html;
}

Then it can be called like this:
PHP Code:
<?php 
echo $extractor->randomComment();

Have you completed the interview?
Reply


Possibly Related Threads…
Thread / Author Replies Views Last Post
Last Post by Toeb
17-Oct-2021, 07:55 PM
Last Post by Steven
09-Jul-2018, 08:40 PM
Last Post by m1155
22-Dec-2012, 03:32 PM
Last Post by Steven
22-Oct-2012, 05:58 PM
Last Post by Steven
17-Jul-2012, 04:17 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)