Gossamer Forum
Home : Products : Links 2.0 : Customization :

Trying to split category name into three columns.

Quote Reply
Trying to split category name into three columns.
Hi All,


Can any one please help me solving my problem. I would like to have my category names split into three columns. Iīm using site_html_templates.pl

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:


Sorry my English

/Lars
Quote Reply
Re: Trying to split category name into three columns. In reply to
The key to what you want to do is the line:

Quote:
my ($half) = int (($#subcat+2) / 2);

Look at the code in sub site_html_print_cat that uses $half, and then adjust it to use 3 columns.
Quote Reply
Re: Trying to split category name into three columns. In reply to
Bobsie, thank you for helping me.


Letīs see, if I get it right, I had to change the code below to:

quote:
--------------------------------------------------------------------------------
my ($half) = int (($#subcat+3) / 3);
--------------------------------------------------------------------------------

Look at the code in sub site_html_print_cat that uses $half, and then adjust it to use 3 columns.

Thereīs no problem to get three 3 columns, but the category names only shows in the left column
and right column. But thereīs not happening anything in the midder column. I donīt know if itīs
me, that cannīt find the problem.

sub site_html_print_cat {
# --------------------------------------------------------
my (@subcat) = @_;
my ($url, $numlinks, $mod, $subcat, $category_name, $description, $output, $i);
my ($half) = int (($#subcat+3) / 3);

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

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

# 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" width="220">\n|;
$output .= qq|<td class="catlist" valign="top" width="220">\n|;
}
$i++;

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

$output .= qq|<ul><li><strong><a class="link" href="$url">$category_name</a></strong> <small class="numlinks">($numlinks)</small> |;

# 3 Day $output .= qq|<small><sup class="new">Ny</sup></small>| if (&days_old($mod) < $db_new_cutoff);

my $days_old = &days_old($mod);
if ($days_old <= 2) { $output .= qq| $new_1|; }
elsif ($days_old <= 7) { $output .= qq| $new_3|; }
elsif ($days_old <= 14) { $output .= qq| $new_7|; }

$output .= qq|<BR>|;
$output .= qq|<span class="descript">$description</span><BR>| if (!($description =~ /^[\s\n]*$/));
$output .= qq|<BR></li></ul>|;
}

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

1;

/Lars
Quote Reply
Re: Trying to split category name into three columns. In reply to
 
Code:
if ($i == $half) {
$output .= qq|</td><td class="catlist" valign="top" width="220">\n|;
$output .= qq|<td class="catlist" valign="top" width="220">\n|;
}
$i++;

The problem may be in the above code. When there was only 2 columns, the value of $i was not a problem and only had to match $half once to print the new table data cell. But with 3 columns, you need to check it twice to see if it equals the value of $half. That means, when it matches the first time (triggering the second column), it must be reset back to 0. So try changing the code above to read:

Code:
if ($i == $half) {
$output .= qq|</td><td class="catlist" valign="top" width="220">\n|;
$output .= qq|<td class="catlist" valign="top" width="220">\n|;
$i = 0;
}
$i++;

I hope this helps.

[This message has been edited by Bobsie (edited May 04, 1999).]
Quote Reply
Re: Trying to split category name into three columns. In reply to
 
Bobsie

Everything is working ok now. A lot of thanks for your help. I appreciate, what you have done for me.

/Lars
Quote Reply
Re: Trying to split category name into three columns. In reply to
hmm... just a warning... don't use +3...

+2 is what it's suppose to be... only the /3 has anything to do with the 3 columns..

plus 2 is just some perl thing..

ok.. here comes the math.. you have 6 categories.. you want it to go into 3 (2 in first, 2 in second, 2 in last) columns.. (FYI.. $#subcat would be equal to 5.. (perl thing)..)

so int((5+3) / 3) would be int(8/3) which is 3... (int rounds up)

so int((5+2) / 3) would be int (7/3) which is 2... (int rounds down)

now you've got a problem.. when you added 3.. it made it so the categories do 3 in each column.. but you only have 6 categories.. it would put them into 2 columns.. as for adding 2 would make it go into 3 columns the proper way.. (the +2 is only a perl thing.. nothing to do with columns.. the / 2 is what you change..)

jerry
Quote Reply
Re: Trying to split category name into three columns. In reply to
 
Quote:
so int((5+3) / 3) would be int(8/3) which is 3... (int rounds up)

so int((5+2) / 3) would be int (7/3) which is 2... (int rounds down)

Sorry, int doesn't round at all. It just truncates the decimal part.
Quote Reply
Re: Trying to split category name into three columns. In reply to
I have modified my formula to this so that i dont get 4 colum problem at last for now it resolved my problem and im working without templates Smile i now have to find how to make letters little smaller.



my ($half) = int ((($#subcat+2) / 3)+1)
Quote Reply
Re: Trying to split category name into three columns. In reply to
Greetings All!

Found this old discussion!

Code:
my (@subcat) = @_;
my ($url, $numlinks, $mod, $subcat, $category_name, $description, $output, $i);
my ($third) = int (($#subcat+2) / 3);

It allows three categories, but it also allows a fourth column to come into play as more categories are added. I would like to restrict it to three columns.

Silverion's fix does not work for templates.Any assistance appreciated.



------------------
www.nzcid.godzone.net.nz
New Zealand Christian Internet Directory




Quote Reply
Re: Trying to split category name into three columns. In reply to
To sum up from what everyone else has said on this subject, use this code in place of what you already have in your site_html_template.pl file.

code:
sub site_html_print_cat {
# --------------------------------------------------------
my (@subcat) = @_;
my ($url, $numlinks, $mod, $subcat, $category_name, $description, $output, $i);
my ($half) = int (($#subcat+3) / 3);

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

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

# 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" width="220">\n|;
$output .= qq|<td class="catlist" valign="top" width="220">\n|;
$i = 0;
}
$i++;

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

$output .= qq|<ul><li><strong><a class="link"
href="$url">$category_name</a></strong> <small class="numlinks">($numlinks)</small>
|;

# 3 Day $output .= qq|<small><sup class="new">Ny</sup></small>| if
(&days_old($mod) < $db_new_cutoff);

my $days_old = &days_old($mod);
if ($days_old <= 2) { $output .= qq| $new_1|; }
elsif ($days_old <= 7) { $output .= qq| $new_3|; }
elsif ($days_old <= 14) { $output .= qq| $new_7|; }

$output .= qq|<BR>|;
$output .= qq|<span class="descript">$description</span><BR>| if (!($description =~
/^[\s\n]*$/));
$output .= qq|<BR></li></ul>|;
}

# Don't forget to end the unordered list..
$output .= "</td></td></tr></table></div>\n";
return $output;
}
Quote Reply
Re: Trying to split category name into three columns. In reply to
Hi ALL
Quote Reply
Re: Trying to split category name into three columns. In reply to
Hi ALL,

Quote:
my (@subcat) = @_;
my ($url, $numlinks, $mod, $subcat, $category_name, $description, $output, $i);
my ($half) = int (($#subcat+3) / 3);
Quote:

MMmm This seems wrong, I thought that this shouldnt be touched!!

I have implemented the above and all was working OK, but now im getting the fourth column appear.

How do i get rid of it??



------------------
Regards
MDJ
http://www.isee-multimedia.co.uk
Quote Reply
Re: Trying to split category name into three columns. In reply to
You can add another category.

To my knowledge, this has never been fixed. When you have ((col#s/3)+1), you get a 4th column. When you add one more category, it goes back to 3 columns with space at bottom of the 3rd. Then if you add one more it goes to 3 even; and the next add takes it back to 4.

I use this, but to keep it to 3 columns, I just add 2 categories after passing a number divisable by 3. Until it gets fixed, that's the only solution I can offer.

Ken