ARCHIVE: How to create a list of links
Introduction
This module came about as a need for a solution "at the time" and was shared on Drupal.org sometime later. One of the requirements was a "list of links" on a page. This page describes how that was done.
First of all, having installed the Janode module create a vocabulary that will be dedicated to the Janodes you create (they can of course live in multiple vocabularies but in order to get a list we need a vocabulary dedicated to Janodes).
Once you have a vocabulary in place make a note of it's vid (vocabulary identification number). The easiest way to do that is, in admin > categories visit the "edit vocabulary" then look at the URL. The number at the end of the URL is your vid (write it down, you will need it later).
For the purposes of the following example this is my link:-
admin/taxonomy/edit/vocabulary/19 so my vid is 19. Replace 19 in the following section with the vid of your vocabulary.
Create the listings page
Now that you have you vid and have created some janodes and applied them to categories from you new vocabulary we'll create a listings page.
From Create content select page and start a new page. In order to create the page you will need to set the "input format" to PHP code as we are about to write a snippet.
Enter the following code into the body of your page. Remember to change the vid from 19 to what ever vid you wrote down ealier.
<?php
$my_vid = 19;
$sql = "SELECT vid, name FROM {vocabulary} WHERE vid = %d ORDER BY name";
$vocabularies = db_query($sql, $my_vid);
$output = "";
while ($avoc = db_fetch_object($vocabularies))
{
$output .= "<li><strong>". check_plain($avoc->name) ."</strong></li>\n"
. getChildTerms(0, $avoc->vid);
}
print "<div class='taxonomy_tree'><p><ul>\n" . $output . "</ul></p></div>\n";
function getNodeCount($tid)
{
$sql = "SELECT COUNT(1) as num "
. "FROM {term_node} "
. "WHERE tid = $tid";
return ($acount = db_fetch_object(db_query($sql)))? $acount->num : 0;
}
function getChildTerms($parent, $vid)
{
$sql = "SELECT td.tid, td.vid, td.name "
. "FROM {term_data} td "
. " JOIN {term_hierarchy} th on th.tid = td.tid "
. "WHERE th.parent = $parent "
. " AND td.vid = $vid "
. "ORDER BY td.weight, td.name ";
$terms = db_query($sql);
$output = "";
while ($aterm = db_fetch_object($terms))
{
$output .= "<li>"
. "<a href='/taxonomy/term/$aterm->tid'>$aterm->name</a> ("
. getNodeCount($aterm->tid).")</li>\n"
. getChildTerms($aterm->tid, $vid);
}
return ($output != "")? "<ul>\n" . check_markup($output) ."</ul>\n" : "";
}
?>Note, this is your starting point. If you want to alter the appearence you will need to play with the code. Also, remember, if you get broken PHP code in the snippet then, at best, the page will not display, at worst you'll break the site (white screen of death!). So be careful.
This page was written because it's a FAQ in the Janode issue queue.
<credit> This snippet was based on this original snippet </credit>. Comments from ajayg rolled into article
