Gossamer Forum
Quote Reply
Alpha Bar

I've been rebuilding Qango after upgrading to LSQL 2.1.1 and one of the features I had in my v1.13 installation was an alpha bar, i.e. [ 0-9 | A | B | C ] etc.

I use 'related@' cats and that's the section I've added this mod to. Anyway, here's what I've come up with - just in case it'll be helpful to anyone else.


Add a new field to your category table:

Name: AlphaBar
Type: ENUM
Index: None
Values: No Yes
Not Null: Yes
Default No

Add the following to SiteHTML.pm:

sub site_html_print_cat_alpha {
# --------------------------------------------------------
# This routine prints out a list of categories.
my $subcat = shift;
my $parent_cat = shift @$subcat;
my $breakpoint = int (($#{$subcat}+1) / $CFG->{build_category_columns}) + ( (($#{$subcat}+1) % $CFG->{build_category_columns}) ? 1 : 0);
my $table_head = $CFG->{build_category_table} || '';
my $width = int (100 / $CFG->{build_category_columns});
my $output = '';
my $i = 0;
my $cat_db = $DB->table('Category');
my $opts = { dynamic => 0 };

if ($breakpoint < 1) {
return $output;

# Print Header.
if ($CFG->{build_category_columns}) {
$output = qq|<table width="100%" cellspacing=0 cellpadding=0 border=0><tr><td width="100%" align="center" valign="top"> [ \n|;

# Figure out if we should use a different template.
if ($parent_cat->{Category_Template} and $parent_cat->{Category_Template} =~ /^[\w-]+$/) {
$opts->{template} = $parent_cat->{Category_Template};

# Go through each subcategory and print it's template.
foreach my $cat_r (@$subcat) {
my $category_url = $CFG->{build_root_url} . "/" . $cat_db->as_url ($cat_r->{Full_Name}) . "/" . $CFG->{build_index};
my $category_name = $cat_r->{Name} =~ m,.*/([^/]+)$, ? $1 : $cat_r->{Name};
$cat_r->{Short_Name} = $category_name;
$cat_r->{URL} = $category_url;

# Set the short name.
if ($cat_r->{Related}) {
if ($cat_r->{RelationName}) {
$cat_r->{Short_Name} = $cat_r->{RelationName};
else {
if (exists $parent_cat->{Name} and ($cat_r->{Short_Name} eq $parent_cat->{Name})) {
my ($short) = $cat_r->{Full_Name} =~ m,([^/]+)/[^/]*$,;
$short and ($cat_r->{Short_Name} = $short);
else {
$cat_r->{Short_Name} = $cat_r->{Short_Name};

# We check to see if we are half way through, if so we stop this table cell
# and begin a new one (this lets us have category names in two columns).
if ($CFG->{build_category_columns}) {
# ($i > 0) and !($i % $breakpoint) and ($output .= qq|</td>\n<td valign="top" width="$width%">\n|);
$output .= Links::user_page ('subcategoryalpha.html', $cat_r, $opts) . " | ";

# Don't forget to end the table properly ..
if ($CFG->{build_category_columns}) {
chop $output;
chop $output;
chop $output;
$output .= qq| ] </td></tr></table>\n|;
return $output;

In Build.pm at sub build_category at
# Get the subcategories and related categories ...

Under $display{category_loop} = [$category]; add:

$display{category_alpha_loop} = [$category];

Update the 'while' statement to reflect the addition of the 'Alpha Bar' check:

while (my $cat = $sth->fetchrow_hashref) {
if (exists $rel{$cat->{ID}}) {
$cat->{Related} = 1;
$cat->{Name} = $rel{$cat->{ID}};
if ($cat->{AlphaBar} eq "Yes") {
push @{$display{category_alpha_loop}}, $cat;
else {
push @{$display{category_loop}}, $cat;


Above $display{category} = Links::SiteHTML::display ('print_cat', $display{category_loop}); add the following:

$display{categoryalpha} = Links::SiteHTML::display ('print_cat_alpha', $display{category_alpha_loop});

... and in the 'else' statement below, above $display{category} = ''; add the following:

$display{categoryalpha} = '';

That takes care of splitting out the 'Alpha Bar' subcategories, so now we just need to add them into the category template.

Make a copy of subcategory.html and call it subcategoryalpha.html (the name is important as it is used by SiteHTML to display the Alpha type cats in a row).

Add the following to the new template:

<a href="<%URL%>"><%Short_Name%></a>

(Obviously you can add any font, colour or style formatting to suit your layout).

And finally, add the following to your category.html template where you want the alpha bar to appear:

<%if categoryalpha%>

If you want to put a category into the alpha bar just update the AlphaBar field to 'Yes'.

I think I've got everything covered (there's bits of code all over my .pm files) but if you have any major problems with it, let me know.

All the best
Quote Reply
Re: [qango] Alpha Bar In reply to

how to use it in the version 2.2.1?

It┤s diferent doesn┤t have the tag display , it┤s like

$tplvars{category} = '';

Quote Reply
Re: [assombracao] Alpha Bar In reply to
Version 1.x hacks/mods are completely (for the most part) incompatible with 2.x versions.

GL3 makes most 2.x code changes incompatible also.

But, that is what the plugin system for 2.x was all about. Most 2x plugins will work with 3.x, with only minor changes.

There have been several alpha-bar type solutions posted, but no one solution has worked for everyone, since everyone seems to have a slightly different need. I realized that when trying to work on the alpha_bar plugin, and it ended up as a mostly start-of-word search program.

You can modify it such that you can print out an alpha bar using a loop, or imported template code, then simply pass in the letter as the query. It allows single letters and start of word searches.

the site I had it (the 2.x search) working on I've been redeveloping for GL3, so some changes have to be made.

I hope to have the revised GL3 version for this reworked shortly.

PUGDOG´┐Ż Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.