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
All the best
Shaun
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
All the best
Shaun