Gossamer Forum
Home : Products : Links 2.0 : Customization :

Is there a Nav menu mod?

Quote Reply
Is there a Nav menu mod?
Has anyone created a mod to make a navigation menu out of the categories and sub categories that could be displayed on the home and category template?

So far I have added this sub to db_util.pl.

This is a sub just like build_select_field with changes to the $output var.

foreach $field (@fields) {
$values{$field} ?
($output .= "<OPTION SELECTED>$field\n") :
($output .= "<option value="$build_root_url/$field/index.html">$field</option\n") ;


sub build_nav_menu {
# --------------------------------------------------------
# Builds a SELECT field based on information found
# in the database definition.
#
my ($column, $value, $name, $mult) = @_;
my ($size, %values);

$name || ($name = $column);
$size || ($size = 1);
# commented out 11/20/2003
#$db_select_fields{'Mult-Subcats'} = join (",", &category_list);

if (! exists $db_select_fields{$column}) {
$db_select_fields{$db_cols[$db_category]} = $db_select_fields{'Mult-Related'} = join (",", &category_list);
# code added for multiple cat mod to show on add - mod forms
if (! exists $db_select_fields{$column} && $column eq "AltCategories" && exists $db_select_fields{'Category'}) { $db_select_fields{$db_cols[$db_alt_cat]} = $db_select_fields{'Mult-AltCategories'} = $db_select_fields{'Category'}} elsif (! exists $db_select_fields{$column} && $column eq "AltCategories" && ! exists $db_select_fields{'Category'}) { $db_select_fields{$db_cols[$db_alt_cat]} = $db_select_fields{'Mult-AltCategories'} = join (",", &category_list);}
# end of multiple cat mod
}
if ($mult) {
@fields = split (/\,/, $db_select_fields{"Mult-$column"});
%values = map { $_ => 1 } split (/\Q$db_delim\E/, $value);
}
else {
@fields = split (/\,/, $db_select_fields{$column});
$values{$value}++;
}
($#fields >= 0) or return "error building select field: no select fields specified in config for field '$column'!";

$output = qq|<SELECT NAME="$name" $mult SIZE=$size><OPTION>---|;
foreach $field (@fields) {
$values{$field} ?
($output .= "<OPTION SELECTED>$field\n") :
($output .= "<option value="$build_root_url/$field/index.html">$field</option\n") ;
}
$output .= "</SELECT>";
return $output;
}

I also made this modification to site_html_templates.pl but commented it out because it didn't work. Tried it in Golbals instead. Didn't work.

# --------------Sub to build the home page-------------------

sub site_html_home {
#tried this here but didn't work, then put nav_menu in globals
#my $nav_menu = &build_nav_menu ("Category", "$in{'Category'}");
return &load_template ('index.html', {
category => $category,
nav_menu => $nav_menu
grand_total => $grand_total,
%globals
});
}



Added to Globals:
nav_menu => $build_nav_menu

When you click build you get a download prompt warning about harmful files, reference: nph-build.cgi.
Can anyone help?

Yes permissions are set correctly.

Thanks
Jake
Quote Reply
Re: [awwa] Is there a Nav menu mod? In reply to
Sorry, don't have time to study code right now, but here is amod that will get you half of what you want; it lists main cats wherever you want them. I have this in use on my site.

http://cgi-resource.co.uk/...s/categorymenu.shtml

Maybe it will help you get what you want...


Leonard
aka PerlFlunkie
Quote Reply
Re: [awwa] Is there a Nav menu mod? In reply to
Here is the code that actually works. nav menu with cat and sub cat stripped of any garbage. All you need to do is declare nav_menu globally in your sitehtml template, and add the <%nav_menu%> on any template for a nav menu.
sub nav_menu {
# --------------------------------------------------------
my (%c, @fields);
open (DB, "<$db_category_name") or &cgierr("unable to open $db_file_name. Reason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB>) {
(/^#/) and next LINE;
(/^\s*$/) and next LINE;
@fields = &split_decode ($_); $c{$fields[$db_main_category]}++;
}
close DB;

# Make a select list out of those names.
$output = qq~ <p align="CENTER"><SELECT onchange=window.location.href=this.options[this.selectedIndex].value; style="font-family: Arial; font-size: 11px" size="1">\n~;
$output .= qq|<OPTION selected>-------Main Directory----</OPTION>\n|;
foreach $field (sort keys %c) {
if ($field =~ m,.*/([^/]+)$,) { $field2 = &build_clean($1); } else { $field2 = &build_clean($field); } $output .= qq|<OPTION value="$build_root_url/$field/index.html">$field2</OPTION>\n|;
}
$output .= qq|</SELECT>|;
return $output;
}



Hope it works for you,

Jake

Last edited by:

awwa: Nov 20, 2003, 7:20 PM
Quote Reply
Re: [awwa] Is there a Nav menu mod? In reply to
awwa,

What cgi modeule do you put that navbar code into?

I'm really new at Perl and links2, so could you please give me a bit more detail on where to put what?
-----------------------------------------------------------
Professional Search Engine Marketing by Position Concepts Professional Consulting in SEM, SEO and PPC.
Quote Reply
Re: [poscon] Is there a Nav menu mod? In reply to
Look at the first post, it says, "So far I have added this sub to db_util.pl." so that's where the sub would go. Then the post above yours has this: "Here is the code that actually works. nav menu with cat and sub cat stripped of any garbage. All you need to do is declare nav_menu globally in your sitehtml template, and add the <%nav_menu%> on any template for a nav menu."

To 'declare globally' means go into site_html_templates.pl, and add this to the top, in with the others that look like it. Before pasting, note the use of commas; after each item except the last one.

nav_menu => $nav_menu

Then put the tag <%nav_menu%> in you templates where you want the menu to appear.


Leonard
aka PerlFlunkie