Blogroll based on Weblinks, linking straight to destination
The alphabetical blogroll is a common staple on many websites. However, because the weblinks.module creates only blocks of recent and most active weblinks -- and because those blocks' items link to the node, and not to the destination -- this custom code in a block (or, if you want, in a node) can produce an alphabetical blogroll from the weblinks nodes on your site.
This snippet uses the "goto" link tracking, so click-throughs are still counted.
<?php
/* This php snippet generates an alphabetical blogroll list
* drawn from weblinks nodes on your site.
* Links connect to destination, not the weblink node.
* Limit is offered as an option.
*/
$nlimit = 100;
$result = db_query(db_rewrite_sql("SELECT n.title, w.lid
FROM {node} n
INNER JOIN {weblinks_node} wn ON n.nid = wn.nid
INNER JOIN {weblinks} w ON wn.lid = w.lid
WHERE n.type = 'weblink'
AND n.status = 1
AND n.moderate = 0
ORDER BY n.title
LIMIT $nlimit"));
$output = '<div class="item-list"><ul>';
while ($node = db_fetch_object($result)) {
$output .= '<li>' . l($node->title, 'weblink/goto/' . $node->lid);
}
$output .= '</ul></div>';
return $output;
?>This snippet has been tested in Drupal 4.6.

Adding description?
I'm fairly knew to Drupal and PHP, but I'm setting up a new site and stumbled across this code which is perfect for my needs.
I have the above code working great but I was wondering if you help me in making the above code display the description that is entered in the weblinks module.
I know the link actually goes into a node page, so if you help me add the code that would output the description entered under every link that would be great.
Thanks.
This code should add the
This code should add the description for each link (the body of the weblink node) to the output. I am new to php as well so forgive any mistakes.
<?php/**
* This php snippet creates an alpha blogroll
* from weblinks nodes of a particular category
* or from a list of categories
* specified in the first line ($taxo_id)
* where list items link directly to the linked website
* and not the node describing the website.
* Click-through tracking is maintained.
*
* To increase/decrease the number of nodes listed
* change the $nlimit value to suit.
*
* This is tested on Drupal 4.6.
*/
$taxo_id = 28; /* if an array of terms, enclose in "" and separate by commas */
$nlimit = 100;
$result = db_query(db_rewrite_sql("SELECT n.title, w.lid, n.body
FROM {node} n
INNER JOIN {term_node} tn USING(nid)
INNER JOIN {weblinks_node} wn ON n.nid = wn.nid
INNER JOIN {weblinks} w ON wn.lid = w.lid
WHERE n.type = 'weblink'
AND n.status = 1
AND n.moderate = 0
AND tn.tid in ($taxo_id)
ORDER BY n.title ASC
LIMIT $nlimit"));
while ($node = db_fetch_object($result)) {
$items[] = l($node->title, 'weblink/goto/' . $node->lid) . '<br /> ' . ($node->body);
}
$output .= theme('item_list', $items);
print $output;
?>
modified version of this: http://drupal.org/node/41234 snippet
Current drupal test site:
www.outmates.org.uk/TestSite/
and this code should work with 4.7
this works with 4.7 using the weblink module from the links package. it also will list the node body as a link title (hover text) rather than in the block itself.
<?php/**
* This php snippet creates a list of urls
* from weblinks nodes of a particular category
* or from a list of categories
* specified in the first line ($taxo_id)
* where list items link directly to the linked website
* and not the node describing the website.
* Click-through tracking is maintained.
*
* To increase/decrease the number of nodes listed
* change the $nlimit value to suit.
*
* This is tested on Drupal 4.7.
*/
$taxo_id = 2; /* if an array of terms, enclose in "" and separate by commas */
$nlimit = 10;
$result = db_query(db_rewrite_sql("SELECT n.nid, n.title, w.lid, nr.body
FROM {node} n
INNER JOIN {term_node} tn USING(nid)
INNER JOIN {links_node} wn ON n.nid = wn.nid
INNER JOIN {links} w ON wn.lid = w.lid
INNER JOIN {node_revisions} nr ON n.nid = nr.nid
WHERE n.type = 'weblink'
AND n.status = 1
AND n.moderate = 0
AND tn.tid in ($taxo_id)
ORDER BY n.title ASC
LIMIT $nlimit"));
while ($node = db_fetch_object($result)) {
$items[] = l($node->title, 'links/goto/' . $node->nid . '/' . $node->lid .'/links_weblink', array(title=>$node->body));
}
$output .= theme('item_list', $items);
print $output;
?>