Login  |  Register
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome, Guest. Please login or register.
Did you miss your activation email?

August 11, 2022, 09:34:11 AM

Login with username, password and session length
Members
  • Total Members: 3842
  • Latest: Kokoro
Stats
  • Total Posts: 193479
  • Total Topics: 21088
  • Online today: 52
  • Online ever: 1035
  • (November 26, 2020, 04:45:12 AM)
Users Online
Users: 0
Guests: 46
Total: 46

Author Topic: [Block] Recent comments on articles.  (Read 34393 times)

0 Members and 1 Guest are viewing this topic.

Offline Freddy

  • Moderator
  • *
  • Posts: 1615
    • AiDreams
[Block] Recent comments on articles.
« on: October 16, 2009, 10:42:31 AM »
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- 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.

Code: [Select]
// 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);
« Last Edit: August 10, 2012, 04:40:52 AM by Freddy »

dimdom

  • Guest
Re: [Block] Recent comments on articles.
« Reply #1 on: October 17, 2009, 04:39:44 AM »
Excellent work freddy!

Here is my modified code to make it look better in a side block:

Code: [Select]
// 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. :)




Offline Renegd98

  • Hero Member
  • *****
  • Posts: 733
Re: [Block] Recent comments on articles.
« Reply #2 on: October 17, 2009, 06:16:37 AM »
Nice work Freddy and dimdom...

mymistake

  • Guest
Re: [Block] Recent comments on articles.
« Reply #3 on: October 17, 2009, 06:25:36 AM »
This is excellent - just what I was looking for. Thanks a lot!

Offline Freddy

  • Moderator
  • *
  • Posts: 1615
    • AiDreams
Re: [Block] Recent comments on articles.
« Reply #4 on: October 17, 2009, 06:42:47 AM »
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  ^-^

Offline Rus

  • Jr. Member
  • **
  • Posts: 31
    • Local Watering Hole
Re: [Block] Recent comments on articles.
« Reply #5 on: May 18, 2011, 04:45:45 PM »
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.

Offline IchBin

  • Friends
  • *
  • Posts: 16231
Re: [Block] Recent comments on articles.
« Reply #6 on: May 19, 2011, 08:37:16 AM »
Updated code from first post. Post back if there are any errors.
Code: [Select]
// *** 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);

Offline Freddy

  • Moderator
  • *
  • Posts: 1615
    • AiDreams
Re: [Block] Recent comments on articles.
« Reply #7 on: May 19, 2011, 08:56:27 AM »
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.

Offline Rus

  • Jr. Member
  • **
  • Posts: 31
    • Local Watering Hole
Re: [Block] Recent comments on articles.
« Reply #8 on: May 20, 2011, 03:18:53 PM »
Worked great.  Thank you!

Offline MrCare

  • Jr. Member
  • **
  • Posts: 62
Re: [Block] Recent comments on articles.
« Reply #9 on: August 06, 2012, 01:17:03 AM »
How we can limit comment character?