Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Categories in a dropdown box?

Quote Reply
Categories in a dropdown box?
Is there a way to put all the categories in a dropdown box at my main homepage?

Thanks,
Emilio
Quote Reply
Re: Categories in a dropdown box? In reply to
Not out of the box no. You could do something like:

Code:
sub category_dropdown {
# -----------------------------------------
# Generate a dropdown list of categories.
#
my $db = new Links: BSQL $LINKS{admin_root_path} . "/defs/Category.def";
my $cats = $db->query ( { ID => '*', sb => 'Name' } );
my $output = '';
if ($db->hits) {
$output = '<SELECT NAME="Category">
foreach my $cat (@$cats) {
$cat = $db->array_to_hash($cat);
$output .= "<OPTION>" . $cat->{Name};
}
$output .= "</SELECT>";
}
else {
$output = "Sorry, we don't have any categories.";
}
return $output;
}

and put that in HTML_Templates.pm. Then add category_list => \&category_dropdown in your GLOBALS list. Then you can use <%category_list%> wherever you like to generate a select list.

Hope that helps,

Alex
Quote Reply
Re: Categories in a dropdown box? In reply to
Okay I'm still trying to make a page with all my categories on it. I trying to figure
this out myself, but it's not going that well. I to modify my HTML_Templates.pm file with the below mentioned modification. It caused a error in line 133 (in the modified file) which was caused by a unknown character \001. I'm really tired now and nothing workes like it's supposed to.

Looking forward to hearing from some of you guys. Please also reply to my category question.

Thanks
Quote Reply
Re: Categories in a dropdown box? In reply to
I just noticed I do have a syntax error in there. It should be:

$output = '<SELECT NAME="Category">';

not:

$output = '<SELECT NAME="Category">

The error message you got sounds like some strange formatting problems. Make sure you sent it over in ASCII mode..

Cheers,

Alex
Quote Reply
Re: Categories in a dropdown box? In reply to
I know most everybody knows this, but reminders are kind on the soul.

1. Remember to change the <space><happy face> with (that's colon : followed by the letter D

Happy Linking

Kyle

[This message has been edited by klangan (edited February 01, 2000).]
Quote Reply
Re: Categories in a dropdown box? In reply to
Here's something I did with Links 2 that accomplishes a similar thing, although much more manual in nature. The up-side is that you don't have to load hundreds or thousands of categories in the select box on each page, you can just pick the main categories and a few important subcategories as a means of easing navigation.

For Links SQL (I haven't switched it over and tested it yet, but I probably will soon), add this above the %GLOBALS section in HTML_templates.pm:
Code:
my $cat_menu = '
<SELECT name="box" size="1" onChange="location.href = document.gothere.box.options[document.gothere.box.selectedIndex].value;">
<option value="http://www.run-down.com/">-- Links Categories --</option>
<option value="http://domain.com/">-----------</option>
<option value="http://domain.com/Cat1">Cat1</option>
<option value="http://domain.com/Cat2">Cat2</option>
<option value="http://domain.com/Subcat2">Subcat2</option>
<option value="http://domain.com/Subcat3">Subcat3</option>
<option value="http://domain.com/Cat3">Cat3</option>
';
Then add cat_menu => $cat_menu, to the %GLOBALS. Wherever you want the category dropdown select list to appear in your templates, add this:

<FORM name="gothere" method="POST">
<%cat_menu%>
</form>

Again, it's not an automated process tied into the categories. However, in the eight months I have used Links, I have never had reason to change my main categories. Some of the "main" subcategories have changed, but it's not too big a deal to occasionally edit the select list in HTML_templates.pm.

Dan
Quote Reply
Re: Categories in a dropdown box? In reply to
p.s. I put the form tags in each template (as opposed to in the $cat_menu variable) just to be safe. It's easy to get improperly nested form tags, and who knows if they would be properly identified in dynamic pages by all browsers. I went ahead and added it in to my Links SQL setup, and it works just fine, as expected.

Dan