Gossamer Forum
Home : Products : Links 2.0 : Customization :

Horizontal category display tweaking

Quote Reply
Horizontal category display tweaking
I've got my categories displaying horizontally across the page. The background color of my table cells is blue, so if the last row in a table has an uneven number of cells, the table is very visibly not squared off. Unfortunately I don't know how to write perl, so I need some help here.

I wonder if there's a way within the formula that calculates the value of the $half variable, to calculate the total count of categories, (is this the #subcat variable?), then subtract that number from the next highest multiple of the divisor of the category count, and then add the difference as that number of table cells.

So it would mean that if you were dividing 17 sub cats into 4 rows, it would figure out that the next multiple of 4 is 20 and so generate 3 extra table cells for you.

The relevant parts of site_html_templates.pl are below:

From sub site_html_print_cat

# Next line divides cat page into columns equal to the number after the / mark in the line

my ($half) = int ((($#subcat+2) / 4)+1);

# Next is step one to sort the categories horizontally with each category in it's own table cell

$output = qq|<div align="center"><table width="90%" border="0" cellspacing="0" cellpadding="3"><tr bgcolor="#BFD5F0">\n|;

# This puts the indicated table closing codes at the end of each category row

if ($i == $half) {
$output .= qq|</td>\n|;
$output .= qq|</tr>\n|;
$output .= qq|<tr>\n|;
$i = 0;
}
$i++;


# The extra number of table cells would go in this line where the cell with the nbsp is

$output .= "</td><td> </tr></table></div>\n";
return $output;
}

Thanks in advance for any help you can give.

Bobb Menk
bmenk@ll.mit.edu

Quote Reply
Re: Horizontal category display tweaking In reply to
Immediately after the end of the foreach loop, add this:
Code:
until ($i == 4) {
$output .= qq|<td> </td>|;
$i++;
}
so it looks like:
Code:
}
until ($i == 4) {
$output .= qq|<td> </td>|;
$i++;
}
$output .= "</tr>\n</table>\n";
return $output;
}
Change '4' in the above codes to the number of cells per row.

Happy Coding,

--Drew
http://www.FindingHim.com
Quote Reply
Re: Horizontal category display tweaking In reply to
Junko

Thanks for the help with this. I put in the code you suggested and it now works for the top level home page.

However, when I go into any given category page that includes subcategories, I get trouble.

The code as entered looks like this:


until ($i == 5) {
$output .= qq|<td> </td>|;
$i++;
}
$output .= "</tr>\n</table>\n";
return $output;
}

What it does to a category page is:
1) Centers all items in the <UL> instead of left justifying
2) Adds blank table cells in the sub-category display area

From that behavior I can infer that
1) Somewhere I've got a <div align="center"></div> that is getting messed with here (I can check that and fix it)

2) The math in your fix doesn't do the same thing to count the number of subcategories within a given category as it does at the top level, but that the subcategory display is getting built using the same part of the code that the entire toplevel home page comes from.

Any ideas on how to get this to work right down through the sub categories? Is there a way to set a variable that checks for the total number of sub cats within a cat and then create a calculation that divides them into columns and knows whether or not to add blank table cells within that display?

Thanks again for any help you can give.

Bobb Menk
bmenk@ll.mit.edu

Quote Reply
Re: Horizontal category display tweaking In reply to
Try just using $half instead.

Happy Coding,

--Drew
http://www.FindingHim.com
Quote Reply
Re: Horizontal category display tweaking In reply to
Not sure where you mean to use it. In place of $i below?

# This should square up the table
until ($i == 5) {
$output .= qq|<td> </td>|;
$i++;
}
$output .= "</tr>\n</table></div>\n";
return $output;
}

Like this:

# This should square up the table
until ($half == 5) {
$output .= qq|<td> </td>|;
$half++;
}
$output .= "</tr>\n</table></div>\n";
return $output;
}

Or do you mean somewhere else in the script. (Sorry to be dense here, but remember I don't know perl).

Thanks.

Bobb

Quote Reply
Re: Horizontal category display tweaking In reply to
I'm sorry... I meant in place of '5'. Anyway, I should have tested that code in Links before posting. Let me give it a second shot and see why it doesn't work. BTW, can you give me a url so I can see what you're seeing?

Happy Coding,

--Drew
http://www.FindingHim.com
Quote Reply
Re: Horizontal category display tweaking In reply to
Sorry - the URL is behind a firewall so you can't see what it looks like.

I tried replacing the 5 with $half per your suggestion, but that breaks the build process when it starts to create the categories.

Other suggestions?

Thanks.

Bobb