Welcome to Geeklog, Anonymous Tuesday, December 10 2024 @ 09:59 pm EST
Geeklog Forums
Top Ten Stories by View
Status: offline
MLimburg
Forum User
Chatty
Registered: 12/17/01
Posts: 35
Location:Adelaide, AU
Howdy. Here's another one. Moved the Top Ten Stories by View as a block.Open lib-custom.php and insert the following:
{
global $_CONF, $_TABLES, $LANG10;
$result = DB_query( "SELECT sid,title,hits FROM {$_TABLES["stories"]} WHERE draft_flag = 0 AND Hits > 0 ORDER BY Hits 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[9] );
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['hits'] );
$stat_templates->parse( 'stat_row', 'statrow', true );
}
$stat_templates->parse( 'output', 'itemstats' );
$retval = $stat_templates->finish($stat_templates->get_var('output'));
} else
{
$retval = $LANG10[10];
}
return $retval;
}
Friends help you move. Real friends help you move bodies.
PHP Code
Text Formatted Code
function phpblock_toptenstoriesbyview(){
global $_CONF, $_TABLES, $LANG10;
$result = DB_query( "SELECT sid,title,hits FROM {$_TABLES["stories"]} WHERE draft_flag = 0 AND Hits > 0 ORDER BY Hits 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[9] );
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['hits'] );
$stat_templates->parse( 'stat_row', 'statrow', true );
}
$stat_templates->parse( 'output', 'itemstats' );
$retval = $stat_templates->finish($stat_templates->get_var('output'));
} else
{
$retval = $LANG10[10];
}
return $retval;
}
This will allow you to call phpblock_toptenstoriesbyview 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( 'toptenstoriesbyview', 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.
18
16
Quote
Status: offline
linker
Forum User
Newbie
Registered: 03/03/07
Posts: 7
I followed the instructions and place the code: $tpl->set_var( 'toptenstoriesbyview', phpblock_toptenstoriesbyview() );
in search.php in order to get my top ten directories showing up in search and nothing happens. Please help.
my website is http://www.alabamafest.com
22
18
Quote
Status: offline
jmucchiello
Forum User
Full Member
Registered: 08/29/05
Posts: 985
Quote by: MLimburg
Text Formatted Code
$result = DB_query( "SELECT sid,title,hits FROM {$_TABLES["stories"]} WHERE draft_flag = 0 AND Hits > 0 ORDER BY Hits desc LIMIT 10" );At a minimum you need to add COM_getPermSQL() to that. You should also add COM_getTopicSQL() to fully follow GL's security setup. You might also want to check that the date of release has passed. Stories can be saved for future release.
Text Formatted Code
$result = DB_query( "SELECT sid,title,hits FROM {$_TABLES["stories"]} WHERE draft_flag = 0 AND Hits > 0 " . COM_getPermSQL('AND') . COM_getTopicSQL('AND') . " ORDER BY Hits desc LIMIT 10" );
20
23
Quote
Status: offline
jmucchiello
Forum User
Full Member
Registered: 08/29/05
Posts: 985
stories should be in single quotes: $_TABLES['stories']
15
23
Quote
linker
Anonymous
Thanks guys. I was unsuccessful, so i settled for add this code to search.php which work great, except i would like to change topic heading from Top Ten Viewed Stories to Top fifty Viewed Stories.
http://www.accentaccounting.net/search.php
// Detailed story statistics
$result = DB_query("SELECT sid,title,hits FROM {$_TABLES['stories']} WHERE (draft_flag = 0) AND (date <= NOW()) AND (Hits > 0)" . COM_getPermSQL ('AND') . $topicsql . " ORDER BY hits DESC LIMIT 50");
$nrows = DB_numRows($result);
if ($nrows > 0) {
$header_arr = array(
array('text' => $LANG10[8], 'field' => 'sid'),
array('text' => $LANG10[9], 'field' => 'hits'),
);
$data_arr = array();
$text_arr = array('has_menu' => false,
'title' => $LANG10[7],
);
for ($i = 0; $i < $nrows; $i++) {
$A = DB_fetchArray($result);
$A['title'] = stripslashes(str_replace('$','$',$A['title']));
$A['sid'] = "<a href=\"" . COM_buildUrl ($_CONF['site_url']
. "/article.php?story={$A['sid']}". "\">{$A['title']}";
$A['hits'] = COM_NumberFormat ($A['hits']);
$data_arr[$i] = $A;
}
$display .= ADMIN_simpleList("", $header_arr, $text_arr, $data_arr);
} else {
$display .= COM_startBlock($LANG10[7]);
$display .= $LANG10[10];
$display .= COM_endBlock();
}
// CLOSE TOP 10 STORIES
20
17
Quote
All times are EST. The time is now 09:59 pm.
- 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