TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

March 28, 2024, 08:44:47 AM

Login with username, password and session length
Members
Stats
  • Total Posts: 195,104
  • Total Topics: 21,212
  • Online today: 199
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 1
  • Guests: 201
  • Total: 202
  • illori

[Block] Recent comments on articles.

Started by freddy888, October 16, 2009, 05:42:31 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Freddy

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.

// 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);

dimdom

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. :)




Renegd98


mymistake

This is excellent - just what I was looking for. Thanks a lot!

Freddy

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  ^-^

Rus

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.

IchBin

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);

Freddy

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.

Rus


MrCare