Subject: Stats for the last 10 articles

Posted on: 16/10/2012 02:09pm
By: Dirk

I've started blogging more regularly and wanted to know if my posts are actually being read. So I hacked stats.php to include a simple list of the last 10 articles and how many hits they got:

PHP Formatted Code
// Views of the last 10 articles

$result = DB_query("SELECT sid,title,hits,UNIX_TIMESTAMP(date) AS day FROM {$_TABLES['stories']} WHERE (draft_flag = 0) AND (date <= NOW()) AND (Hits > 0)" . COM_getPermSQL ('AND') . $topicsql . " ORDER BY date DESC LIMIT 10");
$nrows  = DB_numRows($result);

if ($nrows > 0) {
    $header_arr = array(
        array('text' => $LANG10[8], 'field' => 'sid', 'header_class' => 'stats-header-title'),
        array('text' => $LANG09[17], 'field' => 'dt', 'header_class' => 'stats-header-title'),
        array('text' => $LANG10[9], 'field' => 'hits', 'header_class' => 'stats-header-count', 'field_class' => 'stats-list-count'),
    );
    $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('$','&#36;',$A['title']));
        $A['sid'] = COM_createLink($A['title'], COM_buildUrl($_CONF['site_url']
                  . "/article.php?story={$A['sid']}"));
        $A['dt']  = strftime("%x", $A['day']);
        $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();
}


This section goes before the "Top Ten Commented Stories" section in public_html/stats.php. It should work for the last couple of Geeklog releases but won't work with 2.0.0.

A similar hack for 2.0.0 should be easy to do. Just copy the section "Detailed story statistics", sort by date instead of by hits and add the new column.

bye, Dirk

Re: Stats for the last 10 articles

Posted on: 17/10/2012 04:54pm
By: ::Ben

A similar hack for 2.0.0 should be easy to do. Just copy the section "Detailed story statistics", sort by date instead of by hits and add the new column.


Thanks for the code and the "after sales service" Smile

Ben

Geeklog - Forum
https://www.geeklog.net/forum/viewtopic.php?showtopic=94415