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

How to integrate the amount of comments on a different place?
#1

I'm not sure if this has already been asked, I did find some questions of people who have a similar nature, but none of these solutions worked for me.

What I basically want is to implement the amount of comments (and the rating) on a different area of the page. I was hoping something like <?php $number_of_comments ?> would work, but such a solution seems to be too easy.

So I basically want to show the amount of comments and the rating on the same page, with the same ID. How can I accomplish such thing?
Reply
#2

Hi,

Is the area of the page before or after the script?

If after, try this:
PHP Code:
<?php
require "comments/includes/db/connect.php";
echo
cmtx_number_of_comments();
echo
"<br/>";
echo
cmtx_average_rating();
?>

Have you completed the interview?
Reply
#3

Hello Steven,

Thanks for your answer. It is before the inclusion of the script. I tried your code, but that one doesn't work.
Reply
#4

Okay it's a little more complicated but still possible.

Firstly remove this line from your integration code:
PHP Code:
<?php 
define
('IN_COMMENTICS', 'true');

Now open up comments/includes/commentics.php and change these two lines:
PHP Code:
<?php 
require $path_to_comments_folder . "includes/functions/page.php"; //load functions file for page
require $path_to_comments_folder . "includes/functions/comments.php"; //load functions file for comments

To this:
PHP Code:
<?php 
require_once $path_to_comments_folder . "includes/functions/page.php"; //load functions file for page
require_once $path_to_comments_folder . "includes/functions/comments.php"; //load functions file for comments

Now try this code (remember to change the $page_id line):
PHP Code:
<?php
define
('IN_COMMENTICS', 'true');
require
"comments/includes/db/connect.php";
require
"comments/includes/functions/page.php";
require
"comments/includes/functions/comments.php";
$page_id = "1";
$page_id = cmtx_sanitize($page_id, true, true, true);
echo
cmtx_number_of_comments();
echo
"<br/>";
echo
cmtx_average_rating();
?>

Have you completed the interview?
Reply
#5

Fantastic Smile Many thanks!
Reply
#6

Hi, I've just seen this thread as I need to do something very similar to the OP.

I need to display a list of items on my main page, each item has it's own comments thread which is displayed on a separate page. Next to each item on my main page I need the number of comments associated with that item to be displayed.

I couldn't get the code example you posted to work. What I tried:

I checked commentics.php, I noticed my version looked like this, so I left it alone:
Code:
require_once $cmtx_path . 'includes/functions/page.php'; //load functions file for page
require_once $cmtx_path . 'includes/functions/comments.php'; //load functions file for comments

At the top of my main page I added:
Code:
define ('IN_COMMENTICS', 'true');
require "comments/includes/db/connect.php";
require "comments/includes/functions/page.php";
require "comments/includes/functions/comments.php";

Then in the items loop on the main page I added:
Code:
$page_id = 1;
$page_id = cmtx_sanitize($page_id, true, true, true);
echo "Number of comments: " . cmtx_number_of_comments();
echo "<BR>" . cmtx_average_rating();

When I run this I get an empty string for the number of comments and a 0 for the rating for each item.

I then tried adding:
Code:
$cmtx_identifier = $itemUniqueID
before the page_id = 1 but that didn't help.

Any ideas? Huh

Gromet
Reply
#7

Hi,

Try this code:

PHP Code:
<?php 
/* Remove these 3 lines once it's working */
@error_reporting(-1); //show every possible error
@ini_set('display_errors', 1); //display errors
@ini_set('log_errors', 0); //don't log errors

define('IN_COMMENTICS', 'true');

require
"comments/includes/db/connect.php";
require
"comments/includes/functions/page.php";
require
"comments/includes/functions/comments.php";

global
$cmtx_page_id;
global
$cmtx_mysql_table_prefix;

$cmtx_page_id = "enter_id_of_page_here";
$cmtx_mysql_table_prefix = ""; // in most cases leave blank.

$cmtx_page_id = cmtx_sanitize($cmtx_page_id, true, true);

echo
"Number of comments: " . cmtx_number_of_comments();
echo
"<br/>";
echo
"Average rating: " . cmtx_average_rating();

Have you completed the interview?
Reply
#8

Thanks for the quick reply. I used the code you suggested and I see the following:

Code:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /comments/includes/functions/comments.php on line 524
Number of comments:

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /comments/includes/functions/comments.php on line 550
Average rating: 0

Also, I'm not sure how I get the value for the pageId? Currently I am just hard coding '1'. I am setting an uniqueID against the $cmtx_identifier when someone posts a comment and I assumed it was this I would use to identify the particular comments thread that was associated with each item on my main page.

Many thanks.
Reply
#9

(23-Aug-2013, 04:31 PM)gromet Wrote:  Thanks for the quick reply. I used the code you suggested and I see the following:

Code:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /comments/includes/functions/comments.php on line 524
Number of comments:

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /comments/includes/functions/comments.php on line 550
Average rating: 0

Also, I'm not sure how I get the value for the pageId? Currently I am just hard coding '1'. I am setting an uniqueID against the $cmtx_identifier when someone posts a comment and I assumed it was this I would use to identify the particular comments thread that was associated with each item on my main page.

Many thanks.

I've taken a look at the table structure and created a query which seems to work and returns the number of comments for a given identifier.

Many thanks for taking the time to help me out with this.

Gromet
Reply
#10

(18-Dec-2011, 10:10 PM)Steven Wrote:  Okay it's a little more complicated but still possible.

This seems to be outdated. Is it still doable? Thanks for the awesome script!
Reply


Possibly Related Threads…
Thread / Author Replies Views Last Post
Last Post by Steven
29-Jul-2020, 08:34 AM
Last Post by MattyP
13-Apr-2020, 08:33 PM
Last Post by Steven
03-May-2016, 08:36 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)