Welcome to Geeklog, Anonymous Friday, November 29 2024 @ 06:44 am EST
Geeklog Forums
Top Ten Commented Stories
Status: offline
MLimburg
Forum User
Chatty
Registered: 12/17/01
Posts: 35
Location:Adelaide, AU
Next in the series .. how to get Top Ten Stories (by number of Comments). Again, this has been pulled from the stats page.Open lib-custom.php and insert the following:
{
global $_CONF, $_TABLES, $LANG10;
$result = DB_query( "SELECT sid,title,comments from {$_TABLES['stories']} WHERE draft_flag = 0 AND uid > 1 and comments > 0 ORDER BY comments desc LIMIT 10" );
$nrows = DB_numRows( $result );
$stat_templates = new Template( $_CONF['path_layout'] . 'stats' );
$stat_templates->set_file( array(
'itemstats'=>'itemstatistics.thtml',
'statrow'=>'singlestat.thtml'
));
if( $nrows > 0 )
{
$stat_templates->set_var( 'item_label', $LANG10[8] );
$stat_templates->set_var( 'stat_name', $LANG10[12] );
for( $i = 0; $i < $nrows; $i++ )
{
$A = DB_fetchArray( $result );
$stat_templates->set_var( 'item_url', 'article.php?story=' . $A['sid'] );
$stat_templates->set_var( 'item_text', stripslashes( str_replace( '$','$',$A['title'] )));
$stat_templates->set_var( 'item_stat', $A['comments'] );
$stat_templates->parse( 'stat_row', 'statrow', true );
}
$stat_templates->parse('output','itemstats');
$retval = $stat_templates->finish( $stat_templates->get_var( 'output' ));
} else
{
$retval = $LANG10[13];
}
return $retval;
}
Friends help you move. Real friends help you move bodies.
PHP Code
Text Formatted Code
function phpblock_toptenstoriesbycomments(){
global $_CONF, $_TABLES, $LANG10;
$result = DB_query( "SELECT sid,title,comments from {$_TABLES['stories']} WHERE draft_flag = 0 AND uid > 1 and comments > 0 ORDER BY comments desc LIMIT 10" );
$nrows = DB_numRows( $result );
$stat_templates = new Template( $_CONF['path_layout'] . 'stats' );
$stat_templates->set_file( array(
'itemstats'=>'itemstatistics.thtml',
'statrow'=>'singlestat.thtml'
));
if( $nrows > 0 )
{
$stat_templates->set_var( 'item_label', $LANG10[8] );
$stat_templates->set_var( 'stat_name', $LANG10[12] );
for( $i = 0; $i < $nrows; $i++ )
{
$A = DB_fetchArray( $result );
$stat_templates->set_var( 'item_url', 'article.php?story=' . $A['sid'] );
$stat_templates->set_var( 'item_text', stripslashes( str_replace( '$','$',$A['title'] )));
$stat_templates->set_var( 'item_stat', $A['comments'] );
$stat_templates->parse( 'stat_row', 'statrow', true );
}
$stat_templates->parse('output','itemstats');
$retval = $stat_templates->finish( $stat_templates->get_var( 'output' ));
} else
{
$retval = $LANG10[13];
}
return $retval;
}
This will allow you to call phpblock_toptenstoriesbycomments as a block. In addition (and indeed, the reason it was written in the first place), you can code a template placemarker to get this info. Something like ...
Text Formatted Code
$tpl->set_var( 'storiesbycomments', phpblock_toptenstoriesbyview() );... will give you the ability to place that info pretty much anywhere!
Happy Hacking.
Friends help you move. Real friends help you move bodies.
16
9
Quote
All times are EST. The time is now 06:44 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