As per request here is a block that will show you the most recent comments made on your articles. You can use this in a PHP article or block.
You can configure it to limit the number of comments to show.
I made this similar in appearance to the recent posts block code.
Demo here (http://aidreams.co.uk/forum/index.php?page=121)- not much there though as I stopped using comments as they tend to get lost, but with this maybe I will start using them again. Using my own system now, so no demo on my site.
// Block code to show recent comments made on articles.
// Freddy888 - with some of Bloc's layout code.
// *** Config ***
// Set the maximum number of comments to show.
$limit = 5;
// *** End Of Config ***
// Now the code..
global $scripturl, $db_prefix;
$request = db_query("
SELECT n.value2, n.value3, n.value4, n.value5, m.subject, m.authorID, m.author, m.shortname, o.memberName
FROM {$db_prefix}tp_articles m
INNER JOIN {$db_prefix}tp_variables n
ON n.value5 = m.id INNER JOIN {$db_prefix}members o
ON n.value3 = o.ID_MEMBER
WHERE n.type = 'article_comment'
ORDER BY n.value4 DESC
LIMIT $limit
", __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($request))
{
// Let's make these variable a little more readable...
$details = array(
'commenter' => '<a href="' . $scripturl . '?action=profile;u=' . $row['value3'] . '">' . $row['memberName'] . '</a>',
'comment' => $row['value2'],
'date' => $row['value4'],
'articleid' => $row['value5'],
'subject' => $row['subject'],
'query' => $row['shortname']
);
// Build the output...
echo '
<div class="tborder tp_article_frame">
<div class="catbg tp_subject">
<span class="tp_month">' , $txt['months_short'][date("n", $details['date'])] , '</span>
<span class="tp_thindivider"></span>
<span class="tp_day">' , date("d",$details['date']) , '</span>
<span class="tp_year"> ' , date("Y",$details['date']) , '</span>
' , ($details['query'] != '' ? '<a href="' . $scripturl . '?page=' . $details['query'] . '">' . $details['subject'] . '</a>' : '<a href="' . $scripturl . '?page=' . $details['articleid'] . '">' . $details['subject'] . '</a>') , '
</div>
<div class="tp_articletext">
<div class="tp_details">
<span class="smalltext">' , $details['commenter'] , ' commented :</span>
</div>
<div style="overflow: auto">
' , $details['comment'] , '
</div>
</div>
</div>';
}
mysql_free_result($request);
Excellent work freddy!
Here is my modified code to make it look better in a side block:
// Block code to show recent comments made on articles.
// Freddy888 - with some of Bloc's layout code.
// *** Config ***
// Set the maximum number of comments to show.
$limit = 5;
// *** End Of Config ***
// Now the code..
global $scripturl, $db_prefix;
$request = db_query("
SELECT n.value2, value3, value4, n.value5, m.subject, m.authorID, m.author, m.shortname, o.memberName
FROM {$db_prefix}tp_articles m
INNER JOIN {$db_prefix}tp_variables n
ON n.value5 = m.id INNER JOIN {$db_prefix}members o
ON n.value3 = o.ID_MEMBER
WHERE n.type = 'article_comment'
ORDER BY n.value4 DESC
LIMIT $limit
", __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($request))
{
// Let's make these variable a little more readable...
$details = array(
'commenter' => '<a href="' . $scripturl . '?action=profile;u=' . $row['value3'] . '">' . $row['memberName'] . '</a>',
'comment' => $row['value2'],
'articleid' => $row['value5'],
'subject' => $row['subject'],
'query' => $row['shortname']
);
// Build the output...
echo '
<div class="tborder tp_article_frame">
<div class="catbg tp_subject">
<span class="smalltext"><span class="tp_thindivider"></span>
<span class="smalltext">' , ($details['query'] != '' ? '<a href="' . $scripturl . '?page=' . $details['query'] . '">' . $details['subject'] . '</a>' : '<a href="' . $scripturl . '?page=' . $details['articleid'] . '">' .
$details['subject'] . '</a>') , '</span>
</div>
<div class="tp_articletext">
<div class="tp_details">
<span class="smalltext">' , $details['commenter'] , ' ÃÆ'ÇολίαÃÆ'ε:</span>
</div>
<div style="overflow: auto">
<span class="smalltext">' , $details['comment'] , '</span>
</div>
</div>
</div>';
}
mysql_free_result($request);
No dates and smaller letters. Thats all. :)
Nice work Freddy and dimdom...
This is excellent - just what I was looking for. Thanks a lot!
Thanks Renegd and well done Dimdom, that's perfect for side blocks :)
Glad it's okay mymistake, it was a good idea and worth doing.
The trickiest bit was the SQL, but it's good to learn new tricks ^-^
Do you have any interest in updating this? I'm going to hazard a guess that it doesn't work on either SMF2 or TP1 RC1 because I got errors with it.
Love the idea though.
Updated code from first post. Post back if there are any errors.
// *** Config ***
// Set the maximum number of comments to show.
$limit = 5;
// *** End Of Config ***
// Now the code..
global $scripturl, $db_prefix, $smcFunc, $txt;
$request = $smcFunc['db_query']('', '
SELECT n.value2, n.value3, n.value4, n.value5, m.subject, m.author_id, m.author, m.shortname, o.member_name
FROM {db_prefix}tp_articles m
INNER JOIN {db_prefix}tp_variables n ON n.value5 = m.id
INNER JOIN {db_prefix}members o ON n.value3 = o.id_member
WHERE n.type = {string:type}
ORDER BY n.value4 DESC
LIMIT {int:limit}',
array('type' => 'article_comment', 'limit' => $limit)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
{
// Let's make these variable a little more readable...
$details = array(
'commenter' => '<a href="' . $scripturl . '?action=profile;u=' . $row['value3'] . '">' . $row['member_name'] . '</a>',
'comment' => $row['value2'],
'date' => $row['value4'],
'articleid' => $row['value5'],
'subject' => $row['subject'],
'query' => $row['shortname']
);
// Build the output...
echo '
<div class="tborder tp_article_frame">
<div class="catbg tp_subject">
<span class="tp_month">' , $txt['months_short'][date("n", $details['date'])] , '</span>
<span class="tp_thindivider"></span>
<span class="tp_day">' , date("d",$details['date']) , '</span>
<span class="tp_year"> ' , date("Y",$details['date']) , '</span>
' , ($details['query'] != '' ? '<a href="' . $scripturl . '?page=' . $details['query'] . '">' . $details['subject'] . '</a>' : '<a href="' . $scripturl . '?page=' . $details['articleid'] . '">' . $details['subject'] . '</a>') , '
</div>
<div class="tp_articletext">
<div class="tp_details">
<span class="smalltext">' , $details['commenter'] , ' commented :</span>
</div>
<div style="overflow: auto">
' , $details['comment'] , '
</div>
</div>
</div>';
}
$smcFunc['db_free_result']($request);
Well done IchBin. I had this on my desktop to do but for most of the day I have had really bad eye strain or something. I could barely open my left eye. Feeling a lot better now though touch wood.
Worked great. Thank you!
How we can limit comment character?
You can use substr() on any text to limit it. You can see the examples on this page.
http://php.net/manual/en/function.substr.php
</div>
' , strlen($details['comment']) > 47 ? substr($details['comment'], 0, 47) .'... ' : $details['comment'] , '
</div>
</div>
</div>';
}
$smcFunc['db_free_result']($request);
hope anybody can help ... tq
What do you need help with?
I decided to share my variation of this block of code, in case anybody else is interested in it. Changes I made are as follows:
- Changed it to use the member's screen name (or real name if you like) instead of their log in name.
- Changed the formatting to make it smaller so it fits into a side block easier.
- Added the ability to limit the length of the comment it shows (without slicing up the html characters along the way) with a default of 60 characters.
// *** Config ***
// Set the maximum number of comments to show.
$limit = 5;
$commlim = 60;
// *** End Of Config ***
// Now the code..
global $scripturl, $db_prefix, $smcFunc, $txt;
$request = $smcFunc['db_query']('', '
SELECT n.value2, n.value3, n.value4, n.value5, m.subject, m.author_id, m.author, m.shortname, o.real_name
FROM {db_prefix}tp_articles m
INNER JOIN {db_prefix}tp_variables n ON n.value5 = m.id
INNER JOIN {db_prefix}members o ON n.value3 = o.id_member
WHERE n.type = {string:type}
ORDER BY n.value4 DESC
LIMIT {int:limit}',
array('type' => 'article_comment', 'limit' => $limit)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
{
// Let's make these variable a little more readable...
$details = array(
'commenter' => '<a href="' . $scripturl . '?action=profile;u=' . $row['value3'] . '">' . $row['real_name'] . '</a>',
'comment' => $row['value2'],
'date' => $row['value4'],
'articleid' => $row['value5'],
'subject' => $row['subject'],
'query' => $row['shortname']
);
if (strlen(html_entity_decode($details['comment'])) > $commlim)
$details['comment'] = htmlentities(substr(html_entity_decode($details['comment']), 0, ($commlim-3)) . '...');
// Build the output...
echo '
<div class="tborder tp_article_frame">
<div class="catbg tp_subject" style="font-size: smaller;">
<span class="tp_month">' , $txt['months_short'][date("n", $details['date'])] , '</span>
<span class="tp_thindivider"></span>
<span class="tp_day">' , date("d",$details['date']) , '</span>
<span class="tp_year"> ' , date("Y",$details['date']) , '</span>
' , ($details['query'] != '' ? '<a href="' . $scripturl . '?page=' . $details['query'] . '">' . $details['subject'] . '</a>' : '<a href="' . $scripturl . '?page=' . $details['articleid'] . '">' . $details['subject'] . '</a>') , '
</div>
<div class="tp_articletext" style="font-size: smaller;">
<div class="tp_details" style="overflow: auto">
<span class="smalltext" style="font-size: xx-small;">' , $details['commenter'] , ' commented :</span><br />
' , $details['comment'] , '
</div>
</div>
</div>';
}
$smcFunc['db_free_result']($request);
Thanks! Just used this version and changed the formatting back to regular size. The biggest thing I liked more was using the Screen names instead of logins. :)
Hi,
I found this code which is nearly perfect for me. However, if a comment is posted by a guest, the comment is not showing in this block.
What needs to be changed / added to also show the guest comments?
// *** Config ***
// Set the maximum number of comments to show.
$limit = 25;
$commlim = 90;
// *** End Of Config ***
// Now the code..
global $scripturl, $db_prefix, $smcFunc, $txt;
$request = $smcFunc['db_query']('', '
SELECT n.value2, n.value3, n.value4, n.value5, m.subject, m.author_id, m.author, m.shortname, o.member_name
FROM {db_prefix}tp_articles m
INNER JOIN {db_prefix}tp_variables n ON n.value5 = m.id
INNER JOIN {db_prefix}members o ON n.value3 = o.id_member
WHERE n.type = {string:type}
ORDER BY n.value4 DESC
LIMIT {int:limit}',
array('type' => 'article_comment', 'limit' => $limit)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
{
// Let's make these variable a little more readable...
$details = array(
'commenter' => '<a href="' . $scripturl . '?action=profile;u=' . $row['value3'] . '">' . $row['member_name'] . '</a>',
'comment' => $row['value2'],
'date' => $row['value4'],
'articleid' => $row['value5'],
'subject' => $row['subject'],
'query' => $row['shortname']
);
if (strlen(html_entity_decode($details['comment'])) > $commlim)
$details['comment'] = htmlentities(substr(html_entity_decode($details['comment']), 0, ($commlim-3)) . '...');
// Build the output...
echo '
<div class="tborder tp_article_frame">
<div class="catbg tp_subject" style="font-size: large;">
' , ($details['query'] != '' ? '<a href="' . $scripturl . '?page=' . $details['query'] . '">' . $details['subject'] . '</a>' : '<a href="' . $scripturl . '?page=' . $details['articleid'] . '">' . $details['subject'] . '</a>') , '
</div><B>
<div class="">On
<span class="tp_thindivider"></span>
<span class="">' , date("l",$details['date']) , '</span>
<span class="">' , date("d",$details['date']) , '</span>
<span class="">' , $txt['months_short'][date("n", $details['date'])] , '</span>
<span class=""> ' , date("Y",$details['date']) , '</span>
<span class=""> ' , date("H:i:s",$details['date']) , '</span>
<span class="tp_day"> ' , $details['commenter'] , '</span>
<span class="">commented: </B></span>
<div class="" style="color: #330000; font-size: 16px""><br>
' , $details['comment'] , '
</div>
<br></div>';
}
$smcFunc['db_free_result']($request);
You are using an inner join on the member table. Guests are not members so will not be included. Try a left OUTER join instead...
Thanks @rjen,
Changing
INNER JOIN {db_prefix}tp_variables n ON n.value5 = m.id
INNER JOIN {db_prefix}members o ON n.value3 = o.id_member
into
LEFT OUTER JOIN {db_prefix}tp_variables n ON n.value5 = m.id
LEFT OUTER JOIN {db_prefix}members o ON n.value3 = o.id_member
was indeed the solution.
Do you know what I should add to show "Guest" in case a guest comment is posted?
(https://www.tinyportal.net/index.php?action=dlattach;topic=31176.0;attach=27883;image)
IFNULL(o.member_name, 'Guest') AS member_name
Quote from: tino on November 12, 2018, 08:33:54 PM
IFNULL(o.member_name, 'Guest') AS member_name
Better try...
IFNULL(o.member_name, $txt['tp-guest']) AS member_name
Oh that's great..... but where do I place this code?
Quote from: wildenborch on November 12, 2018, 09:01:43 PM
Oh that's great..... but where do I place this code?
In the SQL in place of the o.memer_name
Hi Tino
You refer to this part?
SELECT n.value2, n.value3, n.value4, n.value5, m.subject, m.author_id, m.author, m.shortname, o.member_name
and change it into:
SELECT n.value2, n.value3, n.value4, n.value5, m.subject, m.author_id, m.author, m.shortname, IFNULL(o.member_name, 'Guest') AS member_name
That does not seem to work.
SELECT n.value2, n.value3, n.value4, n.value5, m.subject, m.author_id, m.author, m.shortname, IFNULL(o.member_name, 'Guest') AS member_name
FROM smf_tp_articles m
LEFT OUTER JOIN smf_tp_variables n ON n.value5 = m.id
LEFT OUTER JOIN smf_members o ON n.value3 = o.id_member
WHERE n.type = 'article_comment'
ORDER BY n.value4 DESC
Works for me on my test site.
I copied this code into my php block but it does not show any results.
Can you post the complete code block?
I only ran it on the MySQL Server, but it changes the member_name to guest as I would expect.
The line with the SELECT is the only one I changed from the code block.
Ah I see.
Well it's not so important (no commenter is a guest comment).
If - in the future - you have some time to look into the code it would be a nice block to implement as a predefined block in a future release.
This one works...
I made a few layout changes too because it was quite bulky in the side block but you get the idea...
// *** Config ***
// Set the maximum number of comments to show.
$limit = 25;
// Set the maximum number of characters per comment to show.
$commlim = 90;
// *** End Of Config ***
// Now the code..
global $scripturl, $db_prefix, $smcFunc, $txt;
$request = $smcFunc['db_query']('', '
SELECT n.value2, n.value3, n.value4, n.value5, m.subject, m.author_id, m.author, m.shortname, o.member_name AS member_name
FROM {db_prefix}tp_articles m
LEFT OUTER JOIN {db_prefix}tp_variables n ON n.value5 = m.id
LEFT OUTER JOIN {db_prefix}members o ON n.value3 = o.id_member
WHERE n.type = {string:type}
ORDER BY n.value4 DESC
LIMIT {int:limit}',
array('type' => 'article_comment', 'limit' => $limit)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
{
// Let's make these variable a little more readable...
$details = array(
'commenter' => '<a href="' . $scripturl . '?action=profile;u=' . $row['value3'] . '">' . $row['member_name'] . '</a>',
'comment' => $row['value2'],
'date' => $row['value4'],
'articleid' => $row['value5'],
'subject' => $row['subject'],
'query' => $row['shortname'],
'id' => $row['value3']
);
if (strlen(html_entity_decode($details['comment'])) > $commlim)
$details['comment'] = htmlentities(substr(html_entity_decode($details['comment']), 0, ($commlim-3)) . '...');
// Build the output...
echo '
<div class="tborder tp_article_frame">
<div class="catbg tp_subject" style="padding: 7px 0px 7px 0px;">
' , ($details['query'] != '' ? '<a href="' . $scripturl . '?page=' . $details['query'] . '">' . $details['subject'] . '</a>' : '<a href="' . $scripturl . '?page=' . $details['articleid'] . '">' . $details['subject'] . '</a>') , '
</div><span style="font:smalltext;">
<div class="">On
<span class="tp_thindivider"></span>
<span>' , date("l",$details['date']) , '</span>
<span>' , date("d",$details['date']) , '</span>
<span>' , $txt['months_short'][date("n", $details['date'])] , '</span>
<span> ' , date("Y",$details['date']) , '</span>
<span> ' , date("H:i:s",$details['date']) , '</span>
<span><b> ' , (($details['id'] <> 0) ? $details['commenter'] : $txt['tp-guest']) , '</b></span>
<span class="">commented: </B></span>
<div class="" style="color: #330000; font-size: 16px""><br>
' ,$details['comment'], '
</div>
<br></div>
</div>';
}
$smcFunc['db_free_result']($request);
(($details['id'] <> 0) ? That looks wrong, shouldn't it be > 0
Quote from: tino on November 14, 2018, 11:51:54 AM
(($details['id'] <> 0) ? That looks wrong, shouldn't it be > 0
That will work too...
Yes this is perfect!
Thank you very much @rjen and Tino!
And for future support requests I shall mention:
"Well it's not so important ....
If - in the future - you have some time to look into it the code it would be a nice .....
;D
Hi Arjan, Tino,
I assume that with TP version 2 the code for showing the comments is no longer working?
// *** Config ***
// Set the maximum number of comments to show.
$limit = 25;
// Set the maximum number of characters per comment to show.
$commlim = 90;
// *** End Of Config ***
// Now the code..
global $scripturl, $db_prefix, $smcFunc, $txt;
$request = $smcFunc['db_query']('', '
SELECT n.value2, n.value3, n.value4, n.value5, m.subject, m.author_id, m.author, m.shortname, o.member_name AS member_name
FROM {db_prefix}tp_articles m
LEFT OUTER JOIN {db_prefix}tp_variables n ON n.value5 = m.id
LEFT OUTER JOIN {db_prefix}members o ON n.value3 = o.id_member
WHERE n.type = {string:type}
ORDER BY n.value4 DESC
LIMIT {int:limit}',
array('type' => 'article_comment', 'limit' => $limit)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
{
// Let's make these variable a little more readable...
$details = array(
'commenter' => '<a href="' . $scripturl . '?action=profile;u=' . $row['value3'] . '">' . $row['member_name'] . '</a>',
'comment' => $row['value2'],
'date' => $row['value4'],
'articleid' => $row['value5'],
'subject' => $row['subject'],
'query' => $row['shortname'],
'id' => $row['value3']
);
if (strlen(html_entity_decode($details['comment'])) > $commlim)
$details['comment'] = htmlentities(substr(html_entity_decode($details['comment']), 0, ($commlim-3)) . '...');
// Build the output...
echo '
<div class="tborder tp_article_frame">
<div class="catbg tp_subject" style="padding: 7px 0px 7px 0px;">
' , ($details['query'] != '' ? '<a href="' . $scripturl . '?page=' . $details['query'] . '">' . $details['subject'] . '</a>' : '<a href="' . $scripturl . '?page=' . $details['articleid'] . '">' . $details['subject'] . '</a>') , '
</div><span style="font:smalltext;">
<div class="">On
<span class="tp_thindivider"></span>
<span>' , date("l",$details['date']) , '</span>
<span>' , date("d",$details['date']) , '</span>
<span>' , $txt['months_short'][date("n", $details['date'])] , '</span>
<span> ' , date("Y",$details['date']) , '</span>
<span> ' , date("H:i:s",$details['date']) , '</span>
<span><b> ' , (($details['id'] > 0) ? $details['commenter'] : $txt['tp-guest']) , '</b></span>
<span class="">commented: </B></span>
<div class="" style="color: #330000; font-size: 16px""><br>
' ,$details['comment'], '
</div>
<br></div>
</div>';
}
$smcFunc['db_free_result']($request);
What should be changed to make it working again?
What makes you assume that?
Quote from: @rjen on March 15, 2021, 04:20:01 PM
What makes you assume that?
Probably the fact I moved the article comments to their own table. The table is now tp_comments and is mapped as per this change.
https://github.com/Tinyportal/TinyPortal/blob/7b6c194a411f3187004f6c5a50b41a41a751214d/install.php#L985
So all the value# need to be changed to their respective new column name and the block updated accordingly.
And I assume that this commmand is affected by this change as well?
index.php?action=tportal;sa=showcomments;showall
this was
index.php?action=tpmod;sa=showcomments;showall
Yes tpmod was changed tportal in a lot of instances. Or if it was an admin area it's tpadmin now.
But have you an idea why index.php?action=tportal;sa=showcomments;showall isn't working (not showing any comment)?
Fred
Quote from: wildenborch on March 15, 2021, 10:28:24 PM
But have you an idea why index.php?action=tportal;sa=showcomments;showall isn't working (not showing any comment)?
Fred
Looking at the code. It seems it was missed in the updates. Not even sure how it's actually called atm, other than manually.
Hi Tino,
I really tried it but I really don't know what I'm doing and what to change or delete.
If you have some time, would you mind changing the script?
Fred
I'll look at it this weekend. The comments one will be a new patch release, probably 2.0.2. I don't know of any other bugs in that one so it might be a while before it's officially released, you can take the earlier release mind.
Thank you Tino.
Quote from: wildenborch on March 17, 2021, 05:02:47 PM
Thank you Tino.
That should fix your articleShowComments issue, its in TPArticle, just replace it with the below.
<?php
function articleShowComments() {{{
global $smcFunc, $scripturl, $user_info, $txt, $context;
if(!empty($_GET['tpstart']) && is_numeric($_GET['tpstart'])) {
$tpstart = $_GET['tpstart'];
}
else {
$tpstart = 0;
}
$mylast = 0;
$mylast = $user_info['last_login'];
$showall = false;
if(isset($_GET['showall'])) {
$showall = true;
}
$request = $smcFunc['db_query']('', '
SELECT COUNT(var.subject)
FROM ({db_prefix}tp_comments AS var, {db_prefix}tp_articles AS art)
WHERE var.item_type = {string:type}
' . ((!$showall || $mylast == 0) ? 'AND var.datetime > '.$mylast : '') .'
AND art.id = var.item_id',
array('type' => 'article_comment')
);
$check = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);
$request = $smcFunc['db_query']('', '
SELECT art.subject, memb.real_name AS author, art.author_id AS author_id, var.subject, var.comment, var.member_id,
var.item_id, var.datetime, mem.real_name AS real_name,
' . ($user_info['is_guest'] ? '1' : '(COALESCE(log.item, 0) >= var.datetime)') . ' AS isRead
FROM ({db_prefix}tp_comments AS var, {db_prefix}tp_articles AS art)
LEFT JOIN {db_prefix}members AS memb ON (art.author_id = memb.id_member)
LEFT JOIN {db_prefix}members AS mem ON (var.member_id = mem.id_member)
LEFT JOIN {db_prefix}tp_data AS log ON (log.value = art.id AND log.type = 1 AND log.id_member = '.$context['user']['id'].')
WHERE var.item_type = {string:type}
AND art.id = var.item_id
' . ((!$showall || $mylast == 0 ) ? 'AND var.datetime > {int:last}' : '') .'
ORDER BY var.datetime DESC LIMIT {int:start}, 15',
array('type' => 'article_comment', 'last' => $mylast, 'start' => $tpstart)
);
$context['TPortal']['artcomments']['new'] = array();
if($smcFunc['db_num_rows']($request) > 0) {
while($row=$smcFunc['db_fetch_assoc']($request)) {
$context['TPortal']['artcomments']['new'][] = array(
'page' => $row['item_id'],
'subject' => $row['subject'],
'title' => $row['subject'],
'comment' => $row['comment'],
'membername' => $row['real_name'],
'time' => timeformat($row['datetime']),
'author' => $row['author'],
'author_id' => $row['authorID'],
'member_id' => $row['member_id'],
'is_read' => $row['isRead'],
'replies' => $check[0],
);
}
$smcFunc['db_free_result']($request);
}
// construct the pages
$context['TPortal']['pageindex'] = TPageIndex($scripturl.'?action=tportal;sa=showcomments', $tpstart, $check[0], 15);
$context['TPortal']['unreadcomments'] = true;
$context['TPortal']['showall'] = $showall;
TPadd_linktree($scripturl.'?action=tportal;sa=showcomments' . ($showall ? ';showall' : '') , $txt['tp-showcomments']);
loadTemplate('TParticle');
$context['sub_template'] = 'showcomments';
if(loadLanguage('TParticle') == false) {
loadLanguage('TParticle', 'english');
};
}}}
?>
The block code you need to replace value1 with subject, value2 with comment, value3 with member_id, value4 with datetime, value5 with item_id, n.type with n.item_type and that should be it.
Thank you very much Tino!
I changed the code in TPArticle.php and this is working.
index.phpindex.php?action=tportal;sa=showcomments;showall;showall will show 15 comments.
I noticed that if you have more then 15 comments you have the possibility to go to page 2 (or 3 etc) but that is not working properly. In fact is will show the result of ?action=tportal;sa=showcomments;showall
Fred
The block code you need to replace value1 with subject, value2 with comment, value3 with member_id, value4 with datetime, value5 with item_id, n.type with n.item_type and that should be it.
I changed the block code into this and this is working perferct!
// *** Config ***
// Set the maximum number of comments to show.
$limit = 25;
// Set the maximum number of characters per comment to show.
$commlim = 90;
// *** End Of Config ***
// Now the code..
global $scripturl, $db_prefix, $smcFunc, $txt;
$request = $smcFunc['db_query']('', '
SELECT comment, member_id, datetime, item_id, m.subject, m.author_id, m.author, m.shortname, o.member_name AS member_name
FROM {db_prefix}tp_articles m
LEFT OUTER JOIN {db_prefix}tp_comments n ON item_id = m.id
LEFT OUTER JOIN {db_prefix}members o ON member_id = o.id_member
WHERE n.item_type = {string:type}
ORDER BY datetime DESC
LIMIT {int:limit}',
array('type' => 'article_comment', 'limit' => $limit)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
{
// Let's make these variable a little more readable...
$details = array(
'commenter' => '<a href="' . $scripturl . '?action=profile;u=' . $row['member_id'] . '">' . $row['member_name'] . '</a>',
'comment' => $row['comment'],
'date' => $row['datetime'],
'articleid' => $row['item_id'],
'subject' => $row['subject'],
'query' => $row['shortname'],
'id' => $row['member_id']
);
if (strlen(html_entity_decode($details['comment'])) > $commlim)
$details['comment'] = htmlentities(substr(html_entity_decode($details['comment']), 0, ($commlim-3)) . '...');
// Build the output...
echo '
<div class="tborder tp_article_frame">
<div class="catbg tp_subject" style="padding: 7px 0px 7px 0px;">
' , ($details['query'] != '' ? '<a href="' . $scripturl . '?page=' . $details['query'] . '">' . $details['subject'] . '</a>' : '<a href="' . $scripturl . '?page=' . $details['articleid'] . '">' . $details['subject'] . '</a>') , '
</div><span style="font:smalltext;">
<div class="">On
<span class="tp_thindivider"></span>
<span>' , date("l",$details['date']) , '</span>
<span>' , date("d",$details['date']) , '</span>
<span>' , $txt['months_short'][date("n", $details['date'])] , '</span>
<span> ' , date("Y",$details['date']) , '</span>
<span> ' , date("H:i:s",$details['date']) , '</span>
<span><b> ' , (($details['id'] > 0) ? $details['commenter'] : $txt['tp-guest']) , '</b></span>
<span class="">commented: </B></span>
<div class="" style="color: #330000; font-size: 16px""><br>
' ,$details['comment'], '
</div>
<br></div>
</div>';
}
$smcFunc['db_free_result']($request);
Quote from: wildenborch on March 17, 2021, 08:06:45 PM
Thank you very much Tino!
I changed the code in TPArticle.php and this is working.
index.phpindex.php?action=tportal;sa=showcomments;showall;showall will show 15 comments.
I noticed that if you have more then 15 comments you have the possibility to go to page 2 (or 3 etc) but that is not working properly. In fact is will show the result of ?action=tportal;sa=showcomments;showall
Fred
Has that ever worked? I can't see in the logic how it did previously.
I really don't know. I started to use the scrip because of the layout.