Well, I got something to work in the new version of links. Don't know if it's the best way, but I only had to do it once and it works in both building and paging. If anyone notices any bugs, please let me know. It may not be as flexible as widgetz, but I think if you tap into the foreach statement you can do alot more with it. I actually need to list out all my subcategories, so I'm not using the foreach to it's potential.
Anyway you can see it working at:
http://www.nmculturenet.org/cgi-bin/webman/page.cgi?g=&t=nmcn&d=1&db=Artisans
So here's what I did:
In HTML_templates.pm
sub site_html_print_cat {
Add to the my list at the top
$sub_category_name, $sub_category_url
Then after
else { $cat_r->{'Days_Old'} = ''; }
Add:
# Get any subcategories
# Check the Links.pm file to see if we've turned on build_sub_categories. I like Alex's advice about making stuff like this optional. So if you want this you have to add this variable to Links.pm and set it to 0 or 1. If you don't remove the first if {}
if ($LINKS{build_sub_categories}) {
my $link_db = new Links:
BSQL $LINKS{admin_root_path} . "/defs/Category.def";
my $subnames = $link_db->get_sub_categories ($cat_r->{'ID'});
my $i = 0;
foreach my $subcat (@$subnames) {
$i ++;
my $sub_category = &build_clean_name ($subcat->{Name});
my $sub_category_url = $LINKS{build_root_url} . "/" . $sub_category . "/";
my $count = $sub_category;
my $last = rindex ($sub_category,"\/");
++$last;
my $short =substr($sub_category, $last, 40);
$short =~ s/_/ /g;
$cat_r->{'sub1'} .= qq~<br><a href="$sub_category_url">$short</a>~;
#The <br> in the line above is the separator
#between the subcategories, so if you want
#them separated by a comma, you'll need to
#use a comma at the end (I'm not sure how to
#get rid of the trailing comma if you do that
#though.
}
}
Now, just add <%if sub1%><%sub1%><%endif%> to subcategory.html.
It works for me anyway.
Also, because I wanted 1 column subcategory listings on the homepage and two column subcategory listings on the Category pages
I copied this subroutine and named it to sub site_html_print_cat_home {
Then changed:
my $breakpoint = int (($#names+1) / $LINKS{build_category_columns}) + ( (($#names+1) % $LINKS{build_category_columns}) ? 1 : 0);
to:
my $breakpoint = int (($#names+1) / $LINKS{build_category_home_columns}) + ( (($#names+1) % $LINKS{build_category_home_columns}) ? 1 : 0);
also changed:
$output .= &load_template ('subcategory.html', {
to:
$output .= &load_template ('subcategoryhome.html', {
In Links.pm I added this variable to determine the number of columns I wanted on the homepage.
$LINKS{build_category_home_columns} = 1;
You'll have to create subcategoryhome.html in your template directory.
Be sure to add site_html_print_cat_home to the list of subroutines at the top of HTML_templates.pm (It won't work otherwise)
#Then in nph-build.cgi sub build_home_page {
Change:
$category = &site_html_print_cat ($root_cat_r) if ($root_cat_r);
to:
$category = &site_html_print_cat_home ($root_cat_r) if ($root_cat_r);
I think that's all.
Again, if there's anything wrong with doing it this way, I hope someone will let me know and offer some better suggestions.
Peace all.
Kyle