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?

February 25, 2021, 12:56:32 PM

Login with username, password and session length
Members
Stats
  • Total Posts: 191924
  • Total Topics: 20952
  • Online Today: 71
  • Online Ever: 1035
  • (November 26, 2020, 04:45:12 AM)
Users Online
Users: 0
Guests: 64
Total: 64

Author Topic: Users Post Count block  (Read 1384 times)

0 Members and 1 Guest are viewing this topic.

Offline darkangel

  • Beta Tester
  • *
  • Posts: 361
Users Post Count block
« on: January 16, 2021, 06:50:11 PM »
Many moons ago I had gotten some code to make a block which emoved the avatars, and added the code for the admins NOT to be included, we talk too much and can't win the prizes offered....LOL
Yes, I did try it, too old so it no workie right.  Can someone rig up the code so that I can insert it or remove what is not needed by our asylum??

« Last Edit: January 17, 2021, 01:25:24 PM by @rjen »
Fantasies Realm  | Fantasy Attic

SMF 2.0.15 | TP 1.2 | many mod addons | variety of themes

Offline @rjen

  • Support Team
  • *
  • Posts: 2777
    • FJR-club Nederland
Re: Users Post Count block
« Reply #1 on: January 17, 2021, 12:51:16 AM »
If you provide the code that does not work we may be able to fix it , without that it is only guessing what you want to do
Running TP2.0.1 on SMF2.0 at: www.fjr-club.nl

Testing TP on SMF2.0
Testing TP on SMF2.1 (latest Github)
Want to check what php version I am testing on? See: PHP Info

Offline @rjen

  • Support Team
  • *
  • Posts: 2777
    • FJR-club Nederland
Re: Users Post Count block
« Reply #2 on: January 17, 2021, 07:57:59 AM »
The search function worked fine for me... I assume this was the code you referred to (?), and I just pasted this in a PHP block in my 2.0.17 forum and it works fine...

Well I just tried this code and it worked fine:

Code: [Select]
global $smcFunc, $scripturl, $modSettings, $context;

// Number of top posters displayed
$topPoster = 45;

// Find the latest poster.
$request = $smcFunc['db_query']('', '
SELECT mem.id_member, mem.show_online, mem.real_name, mem.posts, a.id_attach, a.attachment_type, a.filename
FROM ({db_prefix}members as mem)
LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = mem.id_member)
WHERE ' .($context['user']['is_admin'] ? '1' : 'show_online = 1') . '
ORDER BY posts DESC
LIMIT {int:limit}',
array('limit' => $topPoster)
);

$users = array();

while ($row = $smcFunc['db_fetch_assoc']($request))
{
$users[] = array(
'id' => $row['id_member'],
'name' => $row['real_name'],
'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>',
'posts' => $row['posts'],
'show' => $row['show_online'],

);
}

$smcFunc['db_free_result']($request);

// Output our array of users with avatar, posts, and name
echo '
<table cellpadding="0" cellspacing="10">';

foreach ($users as $user)
{
$admins = array(1,2);
if (in_array($user['id'], $admins))
continue;
echo '
<tr>

<td><h5 style="margin: 4px,0,0,4px;">'.$user['link'].'</h5></td><td><h5 style="margin: 4px,0,0,4px;">'. $user['posts'] .'</h5></td>
</tr>';
}

echo '
</table>';

Note that the exclusion on admins is by poster ID (1 and 2) so you need to adapt this array if you have other users you wish to exclude now...

$admins = array(1,2)
Running TP2.0.1 on SMF2.0 at: www.fjr-club.nl

Testing TP on SMF2.0
Testing TP on SMF2.1 (latest Github)
Want to check what php version I am testing on? See: PHP Info

Offline darkangel

  • Beta Tester
  • *
  • Posts: 361
Re: Users Post Count block
« Reply #3 on: January 17, 2021, 12:52:36 PM »
thank you so much y'all. I have been fighting this sight for ages and now I need to remember how to shrink the font size to fit into the block better.

This was the code I had and used but the silly thing would not work and gave errors. It works great just text is too big.
Fantasies Realm  | Fantasy Attic

SMF 2.0.15 | TP 1.2 | many mod addons | variety of themes

Offline @rjen

  • Support Team
  • *
  • Posts: 2777
    • FJR-club Nederland
Re: Users Post Count block
« Reply #4 on: January 17, 2021, 01:00:26 PM »
I saw the code uses the H5 tag, you can change that...
This is for example with the regular font size and 20 top posters:

Code: [Select]
global $smcFunc, $scripturl, $modSettings, $context;

// Number of top posters displayed
$topPoster = 20;

// Find the latest poster.
$request = $smcFunc['db_query']('', '
SELECT mem.id_member, mem.show_online, mem.real_name, mem.posts, a.id_attach, a.attachment_type, a.filename
FROM ({db_prefix}members as mem)
LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = mem.id_member)
WHERE ' .($context['user']['is_admin'] ? '1' : 'show_online = 1') . '
ORDER BY posts DESC
LIMIT {int:limit}',
array('limit' => $topPoster)
);

$users = array();

while ($row = $smcFunc['db_fetch_assoc']($request))
{
$users[] = array(
'id' => $row['id_member'],
'name' => $row['real_name'],
'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>',
'posts' => $row['posts'],
'show' => $row['show_online'],

);
}

$smcFunc['db_free_result']($request);

// Output our array of users with avatar, posts, and name
echo '
<table cellpadding="0" cellspacing="10">';

foreach ($users as $user)
{
$admins = array(1,2);
if (in_array($user['id'], $admins))
continue;
echo '
<tr>

<td>'.$user['link'].'</td><td style="text-align:right;min-width:4em;">'. $user['posts'] .'</td>
</tr>';
}

echo '
</table>';
Running TP2.0.1 on SMF2.0 at: www.fjr-club.nl

Testing TP on SMF2.0
Testing TP on SMF2.1 (latest Github)
Want to check what php version I am testing on? See: PHP Info

Offline darkangel

  • Beta Tester
  • *
  • Posts: 361
Re: Users Post Count block
« Reply #5 on: January 17, 2021, 01:08:49 PM »
Thanks ever so much, looks fantastic now and we admins are not in there, one of the prizes is nice too... :2funny:
Fantasies Realm  | Fantasy Attic

SMF 2.0.15 | TP 1.2 | many mod addons | variety of themes

Offline @rjen

  • Support Team
  • *
  • Posts: 2777
    • FJR-club Nederland
Re: Users Post Count block
« Reply #6 on: January 17, 2021, 01:25:09 PM »
Marking this solved then
Running TP2.0.1 on SMF2.0 at: www.fjr-club.nl

Testing TP on SMF2.0
Testing TP on SMF2.1 (latest Github)
Want to check what php version I am testing on? See: PHP Info

Offline darkangel

  • Beta Tester
  • *
  • Posts: 361
Re: Users Post Count block
« Reply #7 on: January 17, 2021, 01:28:18 PM »
Thanks I always forget that.
Fantasies Realm  | Fantasy Attic

SMF 2.0.15 | TP 1.2 | many mod addons | variety of themes