Welcome to Geeklog, Anonymous Monday, December 23 2024 @ 06:01 am EST

Geeklog Forums

User Block by article posts


Status: offline

orfilms

Forum User
Regular Poster
Registered: 08/02/05
Posts: 70
I was wondering if there is any way to show a block of site users who have posted articles on the site in order by how many articles posted? I'm not talking forum posts or comments, I'm talking articles. And only the users who have posted articles would appear in the block.

Is this possible?
 Quote

Status: Banned

machinari

Forum User
Full Member
Registered: 03/22/04
Posts: 1512
this works...
Text Formatted Code

//displays top ten article posters by number of articles posted.
function phpblock_article_posters()
{
    global $_TABLES, $_CONF;
    //basic select
    $query = "SELECT a.uid, COUNT(*) as count, b.username FROM {$_TABLES['stories']} a, {$_TABLES['users']} b";
    //get username and don't retrieve anonymous users
    $query .= " WHERE a.uid=b.uid AND a.uid>'1'";
    //check access
    $query .= COM_getPermSQL('and');
    //list users only once
    $query .= " GROUP BY a.uid";
    //order by number of stories to that user--desc
    $query .= " ORDER BY count DESC";
    //limit to highest 10 posters
    $query .= " LIMIT 10";
    //run query
    $result = DB_query($query);
    if (DB_numRows($result) > 0){
        //loop thru result
        $retval = '';
        while ($A = DB_fetchArray($result)){
            //display a username and profile link for each result
            $retval .= '<a href="' . $_CONF['site_url'] . '/users.php?mode=profile&uid=';
            $retval .= $A['uid'] . '">' . $A['username'] . '</a> (' . $A['count'] . ')' . LB;
        }
        return $retval;
    } else return;
}



 

put that into your lib-custom.php and create a new block (of type PHPBLOCK) from the block editor.
 Quote

Status: offline

orfilms

Forum User
Regular Poster
Registered: 08/02/05
Posts: 70
Awesome... thanks a lot.

Is there any way to mod this to make it the last 30 days?
 Quote

Status: Banned

machinari

Forum User
Full Member
Registered: 03/22/04
Posts: 1512
still just the to 10 but now limited to 1 month.. and added a check for the draft flag
Text Formatted Code

//displays top ten article posters by number of articles posted.
function phpblock_article_posters()
{
    global $_TABLES, $_CONF;
    //basic select
    $query = "SELECT a.uid, COUNT(*) as count, b.username FROM {$_TABLES['stories']} a, {$_TABLES['users']} b";
    //get username
    $query .= " WHERE a.uid=b.uid AND a.uid>'1'";
    //results just for last 30 days
    $query .= " AND date >= date_sub(NOW(), INTERVAL 1 MONTH) AND date <= NOW()";
    //check access
    $query .= " AND draft_flag='0'" . COM_getPermSQL('AND');
    //list users only once
    $query .= " GROUP BY a.uid";
    //order by number of stories to that user--desc
    $query .= " ORDER BY count DESC";
    //limit to highest 10 posters
    $query .= " LIMIT 10";
    //run query
    $result = DB_query($query);
    if (DB_numRows($result) > 0){
        //loop thru result
        $retval = '';
        while ($A = DB_fetchArray($result)){
            //display a username and profile link for each result
            $retval .= '<a href="' . $_CONF['site_url'] . '/users.php?mode=profile&uid=';
            $retval .= $A['uid'] . '">' . $A['username'] . '</a> (' . $A['count'] . ')' . LB;
        }
        return $retval;
    } else return;
}

 
 Quote

Status: offline

orfilms

Forum User
Regular Poster
Registered: 08/02/05
Posts: 70
awesome thanks again
 Quote

All times are EST. The time is now 06:01 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content