Posted on: 10/08/05 09:03pm
By: orfilms
Is there any way to hack the advanced search to return most viewed articles. I know that stats.php has the top 10 but I would love to be able to check the top articles within certain dates...
hacking the advanced search to show most viewed
Posted on: 10/09/05 01:44am
By: machinari
See if
this thread[*1] does you any good
...it probably wont i think, having just now actually read your question.
hacking the advanced search to show most viewed
Posted on: 10/09/05 01:48am
By: orfilms
Unless I'm missing something, the thread doesn't help me. I need something to find out what were the 15 most popular stories of the last 10 days and how many views. I thought the easiest way to do this would be the advanced search because you can specify a date range. But it doesn't allow you the option to have the result come back in order of popularity. I was thinking a hack to have that option would work best. But If I could create a static page or block that could do this function that would work as well...
hacking the advanced search to show most viewed
Posted on: 10/09/05 01:53am
By: machinari
mix the one above with
this thread[*2] and you should be on your way to a new block. most popular within a date range
hacking the advanced search to show most viewed
Posted on: 10/09/05 02:00am
By: orfilms
I hate to be a pain, and I'm sorry to bother you again but I heve no idea how to intergrate them? I know very very basic php.... and looking at the two code posts its very clear I have no idea whats going on...
hacking the advanced search to show most viewed
Posted on: 10/09/05 02:22am
By: machinari
this block gives you the most popular, ordered by hits descending, for the last 30 days. editing the date calculations in the query will, obviously, change your results.
you could call another function from within this one that, perhaps allows you to enter a date range, and then that calculation will be built and inserted into this query. easy as pie.
function phpblock_mostPopularbyDate()
{
global $_TABLES, $_CONF;
$result = DB_query("SELECT sid,title,hits FROM {$_TABLES['stories']}
WHERE (draft_flag = 0) AND (date <= NOW()) AND (date >= (DATE_SUB(NOW(), INTERVAL 30 DAY)))"
. COM_getPermSQL ('AND') . " ORDER BY hits desc");
$nrows = DB_numRows($result);
if( $nrows > 0 ){
$string = '';
$popular = array();
for( $i = 0; $i < $nrows; $i++ ){
$A = DB_fetchArray( $result );
$string .= $poplist . '<br>';
$popular[] = '<a href="' . COM_buildUrl( $_CONF['site_url']
. '/article.php?story=' . $A['sid'] ) . '">' . $A['title']
. '</a> (' . $A['hits'] . ')';
}
if( !empty( $popular )){
$poplist = COM_makeList( $popular, 'list-popular-stories' );
}
}
return $poplist;
}
hacking the advanced search to show most viewed
Posted on: 10/09/05 09:33pm
By: orfilms
This worked great... I thank you very much, you've saved my butt more than once!
hacking the advanced search to show most viewed
Posted on: 02/02/06 03:22pm
By: beewee
Great block, Mach, especially for good SERP's. But I how can I limit it to show max 5 or 10 stories, and change the URL's to:
www.mydomain.com/topic ID/article.php/story ID ??
hacking the advanced search to show most viewed
Posted on: 02/02/06 10:53pm
By: machinari
to limit the query, just change this bit of the query, ORDER BY hits desc
, to read ORDER BY hits desc LIMIT 5
.
You should be able to have that URL the way you've specified if you turn on URL rewrite in your config.php. This function uses COM_buildURL(), which is the wrapper for the rewrite engine, afaics. But don't quote me cuz I've never actually used it.
hacking the advanced search to show most viewed
Posted on: 02/03/06 02:38am
By: beewee
Great, thanks, but did you have a good look at the URL I mentioned, I'm using URL-Rewrite to put the stories in the topic directories:
URL/topic ID/article.php/story ID
Like on
this website.
hacking the advanced search to show most viewed
Posted on: 02/03/06 02:53am
By: machinari
OK, so the difference being the topic ID, right?
so let's just forget rewrite and do it manually like you wanted in the first place I think.
try this version, which includes the topic ID in the query as well as the URL redefined:
function phpblock_mostPopularbyDate()
{
global $_TABLES, $_CONF;
$result = DB_query("SELECT sid,tid,title,hits FROM {$_TABLES['stories']}
WHERE (draft_flag = 0) AND (date <= NOW()) AND (date >= (DATE_SUB(NOW(), INTERVAL 30 DAY)))"
. COM_getPermSQL ('AND') . " ORDER BY hits desc LIMIT 5");
$nrows = DB_numRows($result);
if( $nrows > 0 ){
$string = '';
$popular = array();
for( $i = 0; $i < $nrows; $i++ ){
$A = DB_fetchArray( $result );
$string .= $poplist . '<br>';
$popular[] = '<a href="' . $_CONF['site_url'] . '/'
. $A['tid'] . '/article.php/' . $A['sid'] . '">' . $A['title']
. '</a> (' . $A['hits'] . ')';
}
if( !empty( $popular )){
$poplist = COM_makeList( $popular, 'list-popular-stories' );
}
}
return $poplist;
}
hacking the advanced search to show most viewed
Posted on: 02/03/06 07:31am
By: beewee
You made me very happy! I deleted the hits, but it works like a charm, look over
here[*3] , right block on the top. Thanks, Mach!