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

Mod: Alphabar

Quote Reply
Mod: Alphabar
Hi,

I've developed a mod to create a simple 'Alphabar' for sub-categories and thought others may like to use it. You'll end up with a bar above your main categories like this:

[ A | B | C | D | H | J | M | R | S ]

You're not limited to putting single letter categories in it, but it'll probably get quite wide if you use full words and may give undesired formatting results (although I haven't tested it for that!).

The Alphabar and your main sub-categories are two separate tables inside another table, but you can format them how you like!


You'll need to add a new field to your 'Category' table:

Column: Alphabar
Type: CHAR
Form Length: 3
Max Length: 3
Not Null: Yes
Default Value: No
Validation: Yes|No
Index Weight: 0

Then update HTML_Templates.pm at sub site_html_print_cat {:

---------------
sub site_html_print_cat {
# --------------------------------------------------------
# This routine determines how the list of categories will look.
# We now use a table to split the category name up into two columns.
# For each category you can use the following variables:
#
# $url : The URL to go to that category
# $category_name : The category name with _ and / removed.
# $category_descriptions{$subcat}: The category description (if any).
# $numlinks : The number of links inside that category (and subcategories).
# $mod : The newest link inside of that category.
#
my ($subcat, $dynamic) = @_;
my $template = defined $dynamic ? $dynamic->param('t') : undef;
my @names = keys %{$subcat};

my ($output, $catcount, $nonalpha, $alphacatcount, $cat_z, $subcatz, $catalpha, $alphabar, $printalpha, $category_name, $category_url, $i, $cat, $cat_r, @subnames);
my $breakpoint = int (($#names+1) / $LINKS{build_category_columns}) + ( (($#names+1) % $LINKS{build_category_columns}) ? 1 : 0);

$nonalpha = 0;
foreach $catcount (@names) {
$cat_z = $subcat->{$catcount};
$alphacatcount = $cat_z->{Alphabar};
if ($alphacatcount ne "Yes") {
$nonalpha++;
}
}

my $breakpointtest = (($nonalpha+1) / 2);


# Print Header.
$alphabar = qq|<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td valign="top"><center>[|;
$output = qq|<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td valign="top"><ul>\n|;

$i = 0;
foreach $cat (sort @names) {
$cat_r = $subcat->{$cat};

# Get the URL and the Category name.
$catalpha = $cat_r->{Alphabar};
$category_url = $LINKS{build_root_url} . "/" . &build_clean_name ($cat_r->{Name}) . "/";
($cat_r->{Name} =~ m,.*/([^/]+)$,) ? ($category_name = $1) : ($category_name = $cat_r->{Name});
$cat_r->{Short_Name} = $category_name;
$cat_r->{URL} = $category_url;

# If sub-category belongs in the Alphabar place it in the row and set alphabar to printout on category page
if ($catalpha eq "Yes") {
$alphabar .= " <a href=\"$category_url\">$category_name</a> |";
$printalpha = "Yes";
}

# If you are using the three level new, calculate the number of days old.
if ($LINKS{build_days_old}) {
if ($cat_r->{'Has_New_Links'}) {
$cat_r->{'Days_Old'} = &Links::DBSQL::date_diff (&Links::DBSQL::get_date(), $cat_r->{'Newest_Link'});
}
else { $cat_r->{'Days_Old'} = ''; }
}

# 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).
($i and ($i % $breakpointtest)) or ($output .= qq|</ul></td><td valign="top"><ul>\n|);

# Only count+1 for sub-cats that are going in the main sub-cat table and not the ones in the alphabar
if ($catalpha ne "Yes") {

$i++;
defined $dynamic and &load_user ($dynamic, $cat_r);
$output .= &load_template ('subcategory.html', { %$cat_r, %GLOBALS }, undef, $template);
}
}
# Don't forget to end the unordered list..
chop $alphabar;
$alphabar .= qq| ]</center>
</td></tr></table>\n|;
$output .= qq|</ul></td></tr></table>\n|;

# Create a main holding table for the sub-cats
$subcatz = qq|<table width="80%" border="0" cellspacing="0" cellpadding="0"><tr><td valign="top">\n|;

# Add the alphabar table if there are alphabar sub-cats
if ($printalpha eq "Yes") {
$subcatz .= $alphabar;
}

# Add the main sub-cats table
$subcatz .= $output;

# End the holding table for the sub-cats
$subcatz .= qq|</td></tr></table>\n|;

return $subcatz;
}
---------------

Note: To add a category to the Alphabar, modify it and put 'Yes' in the 'Alphabar' field.

Download/View the TEXT version of the mod here:

http://www.qango.com/...threads/alphabar.txt

Enjoy Smile

All the best
Shaun
Quote Reply
Re: Mod: Alphabar In reply to
BTW: You can see an example of the 'Alphabar' here:

http://www.qango.com/...ctors_and_Actresses/

All the best
Shaun

Quote Reply
Re: Mod: Alphabar In reply to
perfect! i am going to try and get this working for 2.0

thanks so much!

http://www.ASciFi.com/ - The Science Fiction Portal
Quote Reply
Re: Mod: Alphabar In reply to
You may just want to point out that some characters have been changed by the forum such as at the end of this sentence......

$alphabar = qq|<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td valign="top"><center>[|;


Paul Wilson.
new - http://www.wiredon.net
Quote Reply
Re: Mod: Alphabar In reply to
Paul,

That's how it should be, it begins the alphabar with a "[" and the alpha sub-cats go in it with spaces at one side and a separator on the other " A |" ... so it looks like this:

[ A |

... then each additional alpha sub-cat is added " x |" ... and the last "|" is chopped for a neat closing bracket " ]"

However, having looked again the forum has removed some of the line breaks here:

$alphabar .= qq| ]</center>
</td></tr></table>\n|;


... it should have < B R >< B R > after the </center> and the </td> should be alongside it in one line, e.g.:

$alphabar .= qq| ]</center>< B R ><B R ></td></tr></table>\n|;

For the full text of the mod go here:

http://www.qango.com/...threads/alphabar.txt

Smile

All the best
Shaun
Quote Reply
Re: Mod: Alphabar In reply to
Ahhh yes.....sorry my eye sight is going.....I was fooled because it looked like a carriage return.

Sorry.

Whats AFAICS or whatever you said.

Paul Wilson.
new - http://www.wiredon.net
Quote Reply
Re: Mod: Alphabar In reply to
Paul,

AFAICS = As far as I can see
AFAIK = As far as I know

All the best
Shaun

Quote Reply
Re: Mod: Alphabar In reply to
Hi,

The forum parses out html which is a bit of a bugger sometimes.....



Paul Wilson.
new - http://www.wiredon.net
Quote Reply
Re: Mod: Alphabar In reply to
Gentlemen, exist a version of this modification for LSQL2.0?
this is a very useful modification and if somebody made it to function with LSQL2.0 please places the instruction in the forum.


For a better world.Cool
http://www.janio.com.br
Quote Reply
Re: Mod: Alphabar In reply to
yes, please. I tried working on it for Links SQL but getting all sorts of permission erorrs (nothing to do with the mod) so need to try again. I am not sure but i don't think it is suitable as a plugin though ?

http://www.ASciFi.com/ - The Science Fiction Portal