Welcome to Geeklog Tuesday, January 18 2022 @ 08:37 am EST

Geeklog Forums

Here's the "Most Popular Articles Block"


Status: offline

DubiousChrisJ

Forum User
Regular Poster
Registered: 10/05/05
Posts: 114
Since I just added this back to my site and had the code up, I figured I would post it for y'all. One of the site regulars helped me cobble it together last year. Add this code to your lib-custom, and call the function in a PHP block.

PHP Formatted Code
function phpblock_mostPopular()
{
    global $_TABLES;
    $result = DB_query("SELECT sid,title,hits FROM {$_TABLES['stories']}
        WHERE (draft_flag = 0) AND (date <= NOW()) AND (hits > 0)"

        . COM_getPermSQL ('AND') . " ORDER BY hits desc LIMIT 10");
    $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;
}
 

Luhme summa dat GL.
 Quote

All times are EST. The time is now 08:37 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