Welcome to Geeklog, Anonymous Saturday, December 21 2024 @ 08:06 pm EST

Geeklog Forums

Topic Links Block


Status: offline

kingsley

Forum User
Junior
Registered: 03/17/05
Posts: 29
Hopefully this hasn't been done before...

This is my first php Block so all feedback is welcome.

I have been trying to think of a better way of putting Topic Specific Links in a block in a more dynamic way than using a "normal" block with static Links. I decided to link the gl_topics and gl_links tables where gl_topics.topic = gl_links.category.

This displays a "Topic Link" block when there are links in a catagory that has the same name as the current topic. You will notice in my comments that I have included a way to have a specific Link Catagory displayed on the home page and I have included 2 different select statements for how the links can be ordered.

Text Formatted Code

/*
        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;
}

 
 Quote

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