Uutiset:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu
Advertisement:

ssi_topPoster help

Aloittaja bobdole2281, elokuu 25, 2013, 09:21:40 IP

« edellinen - seuraava »

bobdole2281

Is some variation of this how I can get the top 4 posters:

// Show the top poster's name and profile link.
function ssi_topPoster($topNumber = 1, $output_method = 'echo')


Can I exclude admins?

Arantor

Well, passing the first parameter as 4 would get the top 4, but you'd have to rewrite the main query to exclude admins. And it'll suck for performance too.

$request = $smcFunc['db_query']('', '
SELECT id_member, real_name, posts
FROM {db_prefix}members
WHERE id_group != 1 AND FIND_IN_SET(1, additional_groups) = 0
ORDER BY posts DESC
LIMIT ' . $topNumber,
array(
)
);
Holder of controversial views, all of which my own.


Biology Forums

In your template,

try:

ssi_topPoster(4);

Arantor

Firstly, you don't put SSI functions in the template, mostly because you should not EVER be calling SSI inside an SMF context (hint: that's why one of the very first lines checks if SMF is already loaded and tries to exit gracefully)

Secondly, that doesn't actually answer the OP's question, i.e. how to do it but also exclude administrators.
Holder of controversial views, all of which my own.


NIAB

I use the following code for my top poster

It helps grab a few other things :)

Koodi ("cTopPoster") [Valitse]

function ssi_ctopPoster($topNumber, $output_method)
{
global $smcFunc, $scripturl, $modSettings, $settings;

// Height and width of avatar
$width = '50px';
$height = '50px';
// Number of top posters displayed
$topNumber = 5;

// Find the latest poster.
$request = $smcFunc['db_query']('', '
SELECT mem.id_member, mem.show_online, mem.real_name, mem.posts, mem.avatar, 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 show_online = 1
ORDER BY posts DESC
LIMIT {int:limit}',
array('limit' => $topNumber)
);

$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'],
'avatar' => array(
    'image' => empty($row['avatar']) ? ($row['id_attach'] > 0 ? 'src="' . (empty($row['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $row['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['real_name'].'" />' : '') : (stristr($row['avatar'], 'http://') ? 'src="' . $row['avatar'] . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['real_name'].'" />' : 'src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($row['avatar']) . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['real_name'].'" />'),
    ),
);
}

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

// Output our array of users with avatar, posts, and name

$i = 0;
$len = count($array);
foreach($users as $user) {
    if ($i == 0) {
echo'<a href="'.$user['href'].'">';
        echo'<table id="cTopT" class="fp_news_link" width="100%" ><td width="42px">';
echo '',empty($user['avatar']['image']) ? '<a href="'.$user['href'].'"><img src="'.$settings['images_url'].'/noavatar.gif" width="'.$width.'" height="'.$height.'" alt="" title="'.$user['name'].'" /></a>' : '<a href="'.$user['href'].'"><img '.$user['avatar']['image'].'</a>';
echo '
</td>
<td><h5 style="margin: 4px;">'.$user['link'].'</h5><h5 style="margin: 4px;">Posts: '. $user['posts'] .'';
echo'</td></table>';
echo'</a>';

$i++;
     } else if ($i == 1) {
echo'<a href="'.$user['href'].'">';
    echo'<table id="cTopT" width="100%" class="fp_news_link"><td width="42px">';
echo '',empty($user['avatar']['image']) ? '<a href="'.$user['href'].'"><img src="'.$settings['images_url'].'/noavatar.gif" width="'.$width.'" height="'.$height.'" alt="" title="'.$user['name'].'" /></a>' : '<a href="'.$user['href'].'"><img '.$user['avatar']['image'].'</a>';
echo '
</td>
<td><h5 style="margin: 4px;">'.$user['link'].'</h5><h5 style="margin: 4px;">Posts: '. $user['posts'] .'';
echo'</td></table>';
echo'</a>';
}

}


Just use this to get it to show :)

Koodi ("Output") [Valitse]

ssi_ctopPoster('5', 'echo');


It shows the top 5 Posters :)

Same thing as a the default, but It gets a little more.
Here's what Mine looks like



When it comes to excluding admins, you should keep them in there. It helps increase competition between users and staff :) Makes the position at the top ever so sweet


thisisedy

Lainaus käyttäjältä: NIAB - elokuu 27, 2013, 08:23:44 IP

Koodi ("cTopPoster") [Valitse]

function ssi_ctopPoster($topNumber, $output_method)
{
global $smcFunc, $scripturl, $modSettings, $settings;

// Height and width of avatar
$width = '50px';
$height = '50px';
// Number of top posters displayed
$topNumber = 5;

// Find the latest poster.
$request = $smcFunc['db_query']('', '
SELECT mem.id_member, mem.show_online, mem.real_name, mem.posts, mem.avatar, 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 show_online = 1
ORDER BY posts DESC
LIMIT {int:limit}',
array('limit' => $topNumber)
);

$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'],
'avatar' => array(
    'image' => empty($row['avatar']) ? ($row['id_attach'] > 0 ? 'src="' . (empty($row['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $row['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['real_name'].'" />' : '') : (stristr($row['avatar'], 'http://') ? 'src="' . $row['avatar'] . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['real_name'].'" />' : 'src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($row['avatar']) . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['real_name'].'" />'),
    ),
);
}

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

// Output our array of users with avatar, posts, and name

$i = 0;
$len = count($array);
foreach($users as $user) {
    if ($i == 0) {
echo'<a href="'.$user['href'].'">';
        echo'<table id="cTopT" class="fp_news_link" width="100%" ><td width="42px">';
echo '',empty($user['avatar']['image']) ? '<a href="'.$user['href'].'"><img src="'.$settings['images_url'].'/noavatar.gif" width="'.$width.'" height="'.$height.'" alt="" title="'.$user['name'].'" /></a>' : '<a href="'.$user['href'].'"><img '.$user['avatar']['image'].'</a>';
echo '
</td>
<td><h5 style="margin: 4px;">'.$user['link'].'</h5><h5 style="margin: 4px;">Posts: '. $user['posts'] .'';
echo'</td></table>';
echo'</a>';

$i++;
     } else if ($i == 1) {
echo'<a href="'.$user['href'].'">';
    echo'<table id="cTopT" width="100%" class="fp_news_link"><td width="42px">';
echo '',empty($user['avatar']['image']) ? '<a href="'.$user['href'].'"><img src="'.$settings['images_url'].'/noavatar.gif" width="'.$width.'" height="'.$height.'" alt="" title="'.$user['name'].'" /></a>' : '<a href="'.$user['href'].'"><img '.$user['avatar']['image'].'</a>';
echo '
</td>
<td><h5 style="margin: 4px;">'.$user['link'].'</h5><h5 style="margin: 4px;">Posts: '. $user['posts'] .'';
echo'</td></table>';
echo'</a>';
}

}


Just use this to get it to show :)

Koodi ("Output") [Valitse]

ssi_ctopPoster('5', 'echo');


This is a new function or its SSI related? Where do i need to place this to show the top5 posters on boardindex ? Tried Load.php but i get blank page forum after . Same thing pasting the code in boardindex.template file .
Using 2.0.7 with no portal mods .

Advertisement: