Gossamer Forum
Home : Products : Links 2.0 : Customization :

tree mod mod

Quote Reply
tree mod mod
I'm not a programmer, but this seems to work, so I thought I'd share it. If you are using the tree mod, but only want the subcategory displayed rather than the whole string, replace the sub build_tree_page in the nph-build.cgi with the following:

# *********************************************** tree modification - begin ****************
sub build_tree_page {
# --------------------------------------------------------
# This routine builds a tree from all links/categories

my ($cat, $url, $dir, @related, $relation, $page_num, $next_page, $numlinks);
my ($linkstree, $output, @categorylist, $depth_old, $depth_new);
local ($category, $links, $title_linked, $title, $total, $category_name, $category_name_escaped);
local ($description, $related, $meta_name, $meta_keywords, $header, $footer, $next, $prev);

# set linkstree to 0 if you want only a tree off all categories
# set linkstree to 1 if you want a tree off all categories and links
$linkstree = 1;

$depth_old = 0;
$url = "$build_root_path/tree$build_extension";
open (CAT, ">$url") or &cgierr ("unable to open category page: $url. Reason: $!");


$output = qq~
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html>

<head>
<title>$build_site_title: Hierarchical Directory</title>
</head>

<BODY BGCOLOR="#FFFFFF" link="#4a007d" alink="#ffcc00" vlink="#4a007d">
<center><a href="/index.html"><img src="/gif/banner4.gif" border=0 alt="LSU Libraries"></a></center>

<p><center><font size=+1><A HREF="$build_root_url/">LSU Library Federal Agency Directory</A> : Hierarchical
Directory of Agencies</font></center></p>

<h1>$build_site_title: Hierarchical Directory</h1>



~;
print CAT $output;

# Go through each category and build the appropriate page.
CATEGORY: foreach $cat (sort keys %category) {
next CATEGORY if ($cat =~ /^\s*$/); # How'd that get in here? =)






# We set up all the variables people can use in &site_html.pl.
($description, $related, $meta_name, $meta_keywords, $header, $footer) = @{$category{$cat}}[2..7];

$title_linked = &build_linked_title ($cat);
$title = &build_unlinked_title ($cat);
$total = ($#{$links{$cat}} + 1) / ($#db_cols + 1);
$category_name = $cat;
$category_name_escaped = &urlencode ($cat);
$category_clean = &build_clean ($cat);


$numlinks = ($#{$links{$cat}} + 1) / ($#db_cols + 1);
@categorylist = split (/\//, $cat);
##ADDED NEXT
@subcategorylist = split(/\//, $subcat);
$depth_new = $#categorylist;
$links = "";
##ADDED NEXT 2
$p = rindex($title, ":")+1;
$zcat = substr($title, $p);

if ($depth_new < $depth_old) {
for ($i = 0; $i <= ($depth_old - ($depth_new + 1)); $i++) {
$links .= "\n</ul>";
}
}

$links .= qq~\n<p><strong class="link">
<a href="$build_root_url/$cat/">$zcat</a></strong>

~;


if ($linkstree == 1) {
for ($i = 0; $i < $numlinks; $i++) {
%tmp = &array_to_hash ($i, @{$links{$cat}});
$links .= &site_html_link (%tmp);
}
$links .= "\n";
}

if ($#{$subcategories{$cat}} >= 0) {
$links .= "\n<ul>";
}

print CAT $links;
$depth_old = $depth_new;
}

$output = qq~
<hr>
<form action="$build_search_url" method="GET">
<h2>Search The LSU Libraries Federal Agency Directory</h2>
<div class="margin">
<table border="0" cellspacing="0" cellpadding="0">
<tr><td><input type="text" size=15 name="query"> <input type=submit value="Search!"></td></tr>
<tr><td><small class="more"><a href="$build_search_url">More search options</a></small></td></tr>
</table>
</div>
</form>
<p><small class="update">Pages Updated On: $date - $time

Links Engine Powered By: <a href="http://www.gossamer-threads.com/">Gossamer Threads Inc.</a></small></p>
</body>
</html>
~;
print CAT $output;

close CAT;
}
# *********************************************** tree modification - end ******************