Gossamer Forum
Home : Products : Links 2.0 : Customization :

mod: category link template

Quote Reply
mod: category link template
Okay I've been thinking about why the category link HTML was never template-ized and couldn't think of any reason why it couldn't work. This only took about an hour to come up with and it worked after a couple partially successful attempts. Hope it works for you guys.

Open site_html_templates.pl and go to sub_site_html_print_cat.

Find:
Code:
# Then we print out the name linked, new if it's new, and popular if its popular.
$output .= qq|<dl><dt><strong><a class="link" href="$url">$category_name</a></strong> <small class="numlinks">($numlinks)</small> |;
$output .= qq|<small><sup class="new">new</sup></small>| if (&days_old($mod) < $db_new_cutoff);
$output .= qq|</dt>|;
$output .= qq|<dd><span class="descript">$description </span></dd>| if (!($description =~ /^[\s\n]*$/));
$output .= qq|</dl>|;
Replace with:
Code:
%cat_rec = (url => $url,
numlinks => $numlinks,
category_name => $category_name,
description => $description,
new => $new
);
if (&days_old($mod) < $db_new_cutoff) {$cat_rec{'new'} = 1}
if ($cat_rec{'description'} !~ /^[\s\n]*$/) {delete: $cat_rec{'description'}}
$output .= &site_html_category_link;
Add this new subroutine:
Code:
sub site_html_category_link {
# --------------------------------------------------------
# This routine is used to display what a category link should
# look like.

return &load_template ('category_link.html', {
%cat_rec,
%globals
});
}
Now create a new template named 'category_link.html', like the following, and place it in your templates directory:
Code:
<a href="<%url%>"><%category_name%></a>
<i>(<%numlinks%>)</i>
<%if new%>
<i><sup>new</sup></i>
<%endif%>
<%if description%>
<%description%>
<%endif%>
Change Log:
9-15-00 : BUG - 'my %cat_rec;' declaration at top of subroutine. Works correctly once removed.

--Drew
Quote Reply
Re: mod: category link template In reply to
GREAT JOB JUNKO !!!


... based in your mod, would be possible to make a select form for subcategories ???


Any ideas ???


Regards,

marcoBR

Quote Reply
Re: mod: category link template In reply to
Dear Junko,

I have Installed Category Link Template but I also have yahoo subcat installed. Do you think they conflict? I don't know. I only see this on my page. Please check it:

www.atlastrading.com/links/pages

This is how this supposed to be looked like?

My second question is: Now that category link is driven by template, how can I customize the look of the categories listings (font size, color, space etc.)? Because this is a mess the way it looks like now. Please help!

This is how my site_html_templates.pl looks like using yahoo style subcat and category link template:

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) = @_;
my ($url, $numlinks, $mod, $subcat, $category_name, $description, $output, $i);
my ($half) = int (($#subcat+2) / 2);

# Print Header.
$output = qq|<div class="margin"><table width="80%" border="0" cellspacing="0" cellpadding="0"><tr><td class="catlist" valign="top">\n|;

foreach $subcat (sort @subcat) {
($description) = @{$category{$subcat}}[2];
($subcatstyle) = @{$category{$subcat}}[8];

# First let's get the name, number of links, and last modified date...
$url = "$build_root_url/" . &urlencode($subcat) . "/";
if ($subcat =~ m,.*/([^/]+)$,) { $category_name = &build_clean($1); } else { $category_name = &build_clean($subcat); }
$numlinks = $stats{"$subcat"}[0];
$mod = $stats{"$subcat"}[1];

# 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 ($i == $half) {
$output .= qq|</td><td class="catlist" valign="top">\n|;
}
$i++;

# Then we print out the name linked, new if it's new, and popular if its popular.


%cat_rec = (url => $url,
numlinks => $numlinks,
category_name => $category_name,
description => $description,
new => $new
);
if (&days_old($mod) < $db_new_cutoff) {$cat_rec{'new'} = 1}
if ($cat_rec{'description'} !~ /^[\s\n]*$/) {delete: $cat_rec{'description'}}
$output .= &site_html_category_link;


if ($subcatstyle =~ m,^\(([^\)]+)\)(\d)$, && $#{$subcategories{$subcat}} >= 0) {
($subcatstyle, $style) = ($1, $2);
$s = 0;
@subcatsub = split (/\|/, $subcatstyle);
$output .= qq~ ~ if ($style eq "1");
foreach $category_name (@subcatsub) {
foreach (sort @{$subcategories{$subcat}}) {
($subcatstyle eq "ALL" && $#subcatsub == 0) ?
($_ =~ m,.*/([^/]+)$, and $category_name = &build_clean($1)) :
($_ eq "$subcat/$category_name" or next);
if ($style eq "1") {
$length += length($category_name);
($length > $subcat_length) and last;
}
if ($s > 0) {
$output .= qq~, ~ and $length += 2 if ($style eq "1");
$output .= qq~ ~ if ($style eq "2");
}
$url = "$build_root_url/" . &urlencode($_) . "/";
$output .= qq~<LI>~ if ($style eq "2");
$output .= qq~<a class="subcat" href="$url">$category_name</a>~;
$s++;
last if ($subcatstyle ne "ALL" && $#subcatsub > 0);
}
}
undef $length;
if ($s < $#{$subcategories{$subcat}}) {
$output .= qq~...~ if ($style eq "1");
}
$output .= qq~<BR>~;
}
else { }}

# Don't forget to end the table..
$output .= "</td></tr></table></div>\n";
return $output;
}

1;

Quote Reply
Re: mod: category link template In reply to
I have responded to your private post. I will not make a version for Subcategories Like Yahoo as it would infring on the author's copyright.

Happy Coding,

--Drew
http://www.FindingHim.com
Quote Reply
Re: mod: category link template In reply to
What if I want to pull in other category fields to the template, like ID, Related (cats), and any future fields?

For example, I've been trying to add a "CatImage" field - presented by AnthroRules in the thread just below - so that I can have a pic on top of the cat title, but for some reason, I can't get the contents of the new CatImage field to show up on the page after the build.

http://www.gossamer-threads.com/...w=collapsed&sb=5

I'm going to try the other thread mentioned by Mark1 for adding a graphic to the category - http://gossamer-threads.com/...pl?ubb=004795:Forum3

However, pulling categories.def content into the cat template is something in general that would be worthwhile in case interesting, new categories.def fields come along.

I think I've been faithful the the suggested code changes mentioned by AnthroRules in the other thread, but this doggie still won't bark.

Have you been able to get other categories.def fields pulled into the template?

Many Thanks.

DT