Recent Topics

1 Aug 05, 2006 03:50    

I've been trying to get a list of members and sort them by number of posts, for te life of me i just can't really get ahold of how classes work :( so I am lost, anyone know of a way to acomplish this? (I searched and founf no info)

you can see what i've done here http://www.pvbeat.com

you can see a list of members "Miembros con mas posts" but its not sorted by number of posts :(

I am using 1.8b

Thanks
Shanti

2 Aug 05, 2006 09:10

Well I finally made my own include to show this, its not the best way but it works, if anyone wants it let me know :)

this code is in NO way clean, and probably does not work on all scenarios, but it gives you an idea BUT if you use a multi-blog site this will show all users for ALL blogs, anyone know how to select only users
from the current blog?

I found a way but it needed 3 SQL calls, that was not good

you can see it in http://www.pvbeat.com also i made a plugin for "most viewed posts"

Las 5 mas vistas = most viewed
Miembros (Numero de posts) = members ( number of posts)

in case anyone wants to check it out.

Shanti

3 Aug 06, 2006 23:18

Yeah that'd be nice to see. Maybe I can make it do the blog-specific thing? Can you post all the code it took to do it? It'd make a nice addition to the [url=http://forums.b2evolution.net/viewforum.php?f=9]Plugins & Hacks[/url] forum (hint hint). I'm guessing an addition to your skin's _main.php file and a new file to add to your skins/skinname folder.

4 Aug 06, 2006 23:28

Create a file named _topmembers.php and add this

<div class="bSideItem">
 <?php

/*this code is in NO way clean, and probably does not work on all scenarios, but it gives you an idea
if you use a multi-blog site this will show all users for ALL blogs, anyone know how to select only users
from the current blog?


Shanti Castillo Gilbert
http://www.pvbeat.com
*/

 //how many members do we want to show?
$howmanymembers = 5;

//change this if you need to
//like is will display "Top 5 Members"

$head_title = 'Top '. $howmanymembers.' Members';

      // we first get our users

		$SQL = "SELECT * from evo_users";
       $popular = $DB->get_results($SQL,ARRAY_A);


/*we then create an array that will contain something like
name = "user 2"
posts = 45
id = 1
*/
		for ($con=0; $con <= count($popular)-1; $con++) {
		$SQL= "SELECT count(*) as count FROM evo_posts WHERE post_creator_user_ID = ".$popular[$con]['user_ID'];
		$counter = $DB->get_results($SQL,ARRAY_A);

//we only want users that have posted something, 0 post users are filtered.
 if ($counter[0]['count'] >= 1){
			$numero_posts[] = array('name' => $popular[$con]['user_nickname'], 'posts' => $counter[0]['count'], 'id' => $popular[$con]['user_ID'] );
          }
		}
/*
we need to sort our array by 'posts'
*/
	foreach ($numero_posts as $key => $row) {
   $name[$key]  = $row['name'];
   $num_posts[$key] = $row['posts'];
}

//Taken from php.net
// Sort the data with posts descending, name ascending
// Add $numero_posts as the last parameter, to sort by the common key
array_multisort($num_posts, SORT_DESC,$name, SORT_ASC, $numero_posts);

//finally we display our memberlist
echo '<h3>'.$head_title.'</h3>';

//simple check too see if  $howmanymembers is smaller than the total users to display

if (count($numero_posts)-1 < $howmanymembers) {	$howmanymembers = count($numero_posts)-1;
}

for ($i=0;$i <= $howmanymembers;$i++) {echo "<a href='";
		$Blog->disp( 'staticurl', 'raw' );
		echo "?author=".$numero_posts[$i]['id']."'>".$numero_posts[$i]['name']."</a> (".$numero_posts[$i]['posts'].")<br>";
}

?>
	</div>

on the _main.php of your skin


<?php  // -------------------------- TOP MEMBERs INCLUDED HERE ----------------------------- 

	require( dirname(__FILE__).'/_topmembers.php');

 // -------------------------- top MEMBERS ends ----------------------------- 

and thats it :)
Shanti

5 Oct 07, 2007 08:01

My users miss this since my move to 2.0.1. Is it possible to turn this into widget under 2.x to be able to simply add to the sidebar?


Form is loading...