Posted on: 03/31/05 01:48pm
By: kingsley
/* phpblock_topiclinksblock() by Eric Kingsley [kingsley@nelug.org] Inspired by the "What's New" Block. This block includes Topic specific links on the topic pages using links obtained from the links table. Where the Link "Catagory" and the "Topic Name" are equal those links are displayed in the block ordered by Link Title. Included is an optional Select statement to order the links by "hits". Just follow the instructions in the code. Also included in the code are instructions for making this block appear on the homepage. */ function phpblock_topiclinksblock() { global $_CONF,$_TABLES,$topic; // Uncomment the following code to include the topiclinksblock on the Homepage. Set the value of $topic // to the value of the Link Catagory that you wish to display in the block. If left commented this block // will not appear on the Homepage. //if( empty( $topic )) //{ // $topic .= "General"; //} // Below are 2 options for the Selection and sort order of the Links you wish to display... // // The first SQL Select (origionally commented) will select links and order them in decending order based on // the number of hits recorded. In order to force a link to the top of the list I suggest manually bumping the // number of hits in the "Link Edit" screen. // // The second SQL Select (origionally uncommented) will select links and put them in alphabetical order by title. // // Both these selections limit the number of returned values to 15 this can be adjusted to your taste. //$result = DB_query( "SELECT lid,url,title FROM {$_TABLES['links']},{$_TABLES['topics']} " // . "WHERE {$_TABLES['links']}.category = {$_TABLES['topics']}.topic and {$_TABLES['topics']}.tid = '" . $topic . "' ORDER BY hits DESC LIMIT 0 , 15" ); $result = DB_query( "SELECT lid,url,title FROM {$_TABLES['links']},{$_TABLES['topics']} " . "WHERE {$_TABLES['links']}.category = {$_TABLES['topics']}.topic and {$_TABLES['topics']}.tid = '" . $topic . "' ORDER BY title ASC LIMIT 0 , 15" ); $nrows = DB_numRows( $result ); for( $i = 1; $i <= $nrows; $i++ ) { $A = DB_fetchArray( $result ); // redirect link via portal.php so we can count the clicks $lcount = COM_buildUrl( $_CONF['site_url'] . '/portal.php?what=link&item=' . $A['lid'] ); // Trim the length if over 25 characters $itemlen = strlen( $A['title'] ); if( $itemlen > 25 ) { $retval .= '<a href="' . $lcount . '" title="' . $A['title'] . '">' . substr( $A['title'], 0, 22 ) . '...</a><br>' . LB; } else { $retval .= '<a href="' . $lcount . '">' . substr( $A['title'], 0, $itemlen ) . '</a><br>' . LB; } } return $retval; }