Gossamer Forum
Home : Products : Links 2.0 : Customization :

Subcats count for table cells

Quote Reply
Subcats count for table cells
My Links 2 page is almost done. What is missing is the correct formatting of the subcategories that appear on the main page thanks to the Subcat 2 mod.
The script just take into account the number of categories (8 in my case) and split them between two cells of a table. But under the first category I've got a series of 12 subcategories, which of course shift down the left cell contents.

Is there a way to change the site_html_templates.pl file so the sub site_html_print_cat routine takes into account also the number of subcategories, when splitting the main page contents into two table cells?

You can find my site_html_templates.pl code here (at the bottom of the page)

and my Links 2 page in progress here

Any help would be greatly appreciated!

Diego

Last edited by:

Nightjar: Mar 8, 2003, 1:10 AM
Quote Reply
Re: [Nightjar] Subcats count for table cells In reply to
the url to your links pages did not work. I did find a links option to click on at your site. not sure if that is what you wanted us to see.

the original code just printed the categories and thus it was easy to get equal length columns. But when you add in the subcats, well, you see the problem.

the break point is determined by
my ($half) = int (($#subcat+2) / 2);

Since I think the number of categories at most links site does not change very often, I suggest "hard-coding" the variable. The programmers will want to do this by hacking the code and that is fine too. I set mine 2 yrs ago and haven't changed it since.

my ($half) = 4; # or pick a number that works.

Another thing that I did was to change the order in which I printed the caterories. This won't work in all cases. But if you can control the order and the order doesn't really matter, then this might work without having to hard code the break point.


Gene
"The older I get, the more I admire competence, just simple competence in any field from adultery to zoology."
Quote Reply
Re: [esm] Subcats count for table cells In reply to
Hmm... The second link on my previous message is working (at least on my browser)... Anyway, here is the complete address:

http://www.stonepages.com/megalinks/index.html

I've tried to hard code the my ($half) variable, but setting its value either to 2, 4 or 6 didn't change my table at all.

So, right now on my main page there is a total of 23 categories and subcategories. But 16 of them are on the left table cell, while only 7 are on the right cell. I'm looking a way to show 12 categories and subcategories on the left and 11 on the right. Or - that would be OK too - Just the first category with its 12 subcategories on the left and the resto on the right.

Any other suggestion?

Thanks

Diego
Quote Reply
Re: [Nightjar] Subcats count for table cells In reply to
well, looking at your code, it should work

Did you re-build the pages?

Do the following:

set $half
my ($half) = 1;


and enter the following right after it
print qq|<!-- mod to set the number of columns -->|;

then re-build your links pages

Check out the category page

If you do not see the a change, view the source code and see if you can locate the
<!-- mod to set the number of columns -->

That should tell you if the page was build using $half = 1


Gene
"The older I get, the more I admire competence, just simple competence in any field from adultery to zoology."
Quote Reply
Re: [esm] Subcats count for table cells In reply to
YES!!! It works!
Thanks a million: that's just what I needed!

Diego Smile
Quote Reply
Re: [Nightjar] Subcats count for table cells In reply to
looks good...but what happened to the breaks between the subcats?

England (40)Europe (general) (7)France (11)Great Britain (general) (17)Iberian peninsula (12)Ireland (16)Italy (11)Other U.K. sites (2)Rest of Europe (19)Rest of the World (12)Scotland (27)Wales (5)

The were previously listed one under another. Did you make other changes?


Gene
"The older I get, the more I admire competence, just simple competence in any field from adultery to zoology."
Quote Reply
Re: [esm] Subcats count for table cells In reply to
Well, I was trying to get rid of a bug of the "Nonenglish text" mod which does not list the categories names on the top of subcategories' navigation bar . Try to click on the "Archaeoastronomy" link: on the new page you will see "Top : : Archaeoastronomy" instead of "Top : Other : Archaeoastronomy". I'm still looking for a solution. The mod's creator suggested me to add the name of the category and then an inversed slash. This method works for the categories/subcategories pages but makes a mess on the home page (have a look now: http://www.stonepages.com/megalinks/)

And I've got another problem:
Following your advice, I opted for my ($half) = 1;
But now the categories' pages that do have many subcategories to show, follow the same principle: a single subcategory on the left cell and all the others on the right cell.
Is there a method to keep the my ($half) = 1; variable valid for the main page only?

Still working hard...

Diego
Quote Reply
Re: [Nightjar] Subcats count for table cells In reply to
Below is some code that will fix the breadcrumb nav problem that the nonenglish mod has. It still has problems on spanned pages, but oh well...

To level out out your subcats: if you're using css, define a box height to contain them. Otherwise, seems defing a cell height would work. Css would be like this:

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

# $output .= qq|<tr><td>\n|;
$output .= qq|<div class="home6e">\n|;
$output .= qq|<span class="home6d">\n|;

$output .= qq|<a class="boldnav" href="$url">$category_name</a>
<span class="smalltype">($numlinks)</span>\n|;

Don't forget to </div>

XXXXXXXXXXXXXXx This from nph-build.cgi

# ***************************************** nonenglish modification - begin ****************
# $title_linked = &build_linked_title ($cat);
# $title = &build_unlinked_title ($cat);
# $total = ($#{$links{$cat}} + 1) / ($#db_cols + 1);
# $category_name = $cat;
# $category_name_escaped = &urlencode ($cat);
# $category_clean = &build_clean ($cat);
$total = ($#{$links{$cat}} + 1) / ($#db_cols + 1);

##!!begin nonenglish fix**************************

@categorylist = split (m:/:, $cat);
$depth_new = $#categorylist;
if ($depth_old >= $depth_new) {
for ($i = $depth_new; $i <= $depth_old; $i++) {
pop(@kategorylist);
}
}
$depth_old = $depth_new;
if ($nonenglish eq "") {
push(@kategorylist, $categorylist[$#categorylist]);
$title_linked = &build_linked_title ($cat);
$title = &build_unlinked_title ($cat);
$category_name = $cat;
$category_name_escaped = &urlencode ($cat);
$category_clean = &build_clean ($cat);
}
else {
push(@kategorylist, $nonenglish);
$nonenglishfull = join('/', @kategorylist);
$title_linked = &build_linked_title_mb ($cat, $nonenglishfull);
$title = &build_clean_mb ($cat, $nonenglishfull);
##XXXXXXXXXXXXXXXXXXXXXXXXXXXXX^^^^^^^^
$category_name = &build_last_title_mb ($nonenglish);
$category_name_escaped = &build_last_title_mb ($nonenglish);
$category_clean = &build_clean_mb ($nonenglish);
}

##!!End fix****************************

# ***************************************** nonenglish modification - end ******************



# ***************************************** nonenglish modification - begin ****************
# $title_linked = &build_linked_title ("$cat/Page_$page_num/");
# $title = &build_unlinked_title ("$cat/Page_$page_num/");
if ($nonenglish eq "") {
$title_linked = &build_linked_title ("$cat/Page_$page_num/");
$title = &build_unlinked_title ("$cat/Page_$page_num/");
}
else {

##!!begin nonenglish fix************************
$title_linked = &build_linked_title_mb ("$cat/Page_$page_num/", "$nonenglish\\Page $page_num\\");
$title = &build_clean_mb ("$nonenglish\\Page $page_num\\");
}
##!!end fix********************

# ***************************************** nonenglish modification - end ******************


Leonard
aka PerlFlunkie
Quote Reply
Re: [Nightjar] Subcats count for table cells In reply to
yeah, links takes lots of hard work...Shocked

well, you got some things fixed. For the subcats you need to use just the subcat and not the whole cat : subcat name. And the indenting is wrong on the right side. but you see all that, I am sure and are working hard to fix it.

as for the problem with the subcat pages, I can think of a couple of solutions.

First, I was going to suggest taking a look at http://www.bobsgoodstufflists.net/mtemplates_mod.html. But the problem is in site_html_print_cat not sub site_html_category. So forget that.

Next, you could clone site_html_print_cat, give it a new name and change the name. Edit the new routine to print the category page as you want. Maybe even apply the above mod by Bob Conners.

it looks like the main page is built in nph-build at build_home_page and the category pages at build_category_pages. so, locate the site_html_print_cat name(s) in the build_category_pages routine and change them to the new routine you just create above.

I like that way. Seems logical to separate the main page and the category pages.

Another way would be to create a variable in the two sub routines above to contain the break point that the site_html_print_cat routine would use.

In the two nph-build routines do something like

in build_home_page
my $half = 1;

and

in build_category_pages
my $half = 4;

then in the site_html_print_cat

delete the my $half = 1;

I think the $half variable can still be "seen" by site_html_print_cat routine in the site_html_templates file.

This way is not as flexible.

I did this quickly and got to run - which means I may have made some mistakes...Blush


Gene
"The older I get, the more I admire competence, just simple competence in any field from adultery to zoology."
Quote Reply
Re: [esm] Subcats count for table cells In reply to
Thanks for your suggestions, but I'm still fighting against the intricacies of code customization...

To PerlFlunkie:

I tried to apply your code to my nph-build.cgi file. I checked it three times but the result is always the same. Instead of showing on the navigation top bar (for instance):
Top : Megalithic & Prehistoric sites : England
it shows
Top : : Megalithic & Prehistoric sites/England
And the right link (Megalithic & Prehistoric sites/England) is NOT active.
Apparently, there is something related to the "/" sign that does not work.
Regarding your suggestion to use CSS to level out my subcats, can you please send me your config for the classes you used on your example (home6e, home6d, boldnav)? I haven't fully understood your technique...

To Gene/esm:

I tried to apply the second technique you suggested, putting my ($half) = X into two subroutines of my nph-build file. But that didn't work, because the result was always a single cell, with all the cats and subcats listed on the left. I will try the first mod you suggested, even if it looks more complicated.

It's much harder than I supposed!

Diego

Last edited by:

Nightjar: Mar 9, 2003, 4:21 AM
Quote Reply
Re: [Nightjar] Subcats count for table cells In reply to
I'm just getting going today.....so give me some time

if you use the second option ( declaring $half in the two routines ), instead of
my $half=3;

use
$half=3;

Using the my function does not pass the value to the site_html_print_cat routine.

I'll do a little more work on this and your other problem later today...


Gene
"The older I get, the more I admire competence, just simple competence in any field from adultery to zoology."
Quote Reply
Re: [Nightjar] Subcats count for table cells In reply to
well, I finally got the second one to work. Messy but primarily because I used three columns instead of two which ultimately required the use of the modulus function and I tried using the $half = int (($#subcat+2) / 3); for the category pages.

I may try to use the first method. Like I said, I think this makes more sense since it allows for two different pages.


Gene
"The older I get, the more I admire competence, just simple competence in any field from adultery to zoology."
Quote Reply
Re: [esm] Subcats count for table cells In reply to
OK Gene, thanks to your help, I've finally got the subcategories to be listed differently on the main page and on the secondary pages. I used your method number two, using $half=1; for the main page and $half=6; for the secondary pages.

Now the last bit to be fixed is the top navigation bar on the subcategories pages. According to Matthias Berndt, the developer of "Non English text" mod, I should rename each "non English" text field as follows:

main category\non english name

I tried that and it works, because apparently the inverted slash (\) put things straight on the top navigation bar. But that makes the main categories appear besides each subcategory also on the main page, which is something I cannot leave as it is...

Any idea?

Last edited by:

Nightjar: Mar 9, 2003, 1:58 PM
Quote Reply
Re: [Nightjar] Subcats count for table cells In reply to
glad you got it to work. I've been working on the first method and it looks good so far.Just copied the site_html_print_cat, placed it right after the exisiting and changed the name. then changed one occurence of site_html_print_cat in sub build_category_pages of nph-build. Works like a charm.

I don't have the non-english mod installed and I'm not that good with perl, so I'm flying in the dark here. and i'm not sure what your curent site_html_print_cat looks like.

but do you have the following

$subcats .= qq|/$build_index">|;

I beleive that will produce what you are referring to...


Gene
"The older I get, the more I admire competence, just simple competence in any field from adultery to zoology."
Quote Reply
Re: [Nightjar] Subcats count for table cells In reply to
Sorry, forgot that this was changed, also:



sub build_linked_title_mb {
# --------------------------------------------------------
# Returns a string of the current category broken up
# by section, with each part linked to the respective section.

my ($input) = $_[0];
my ($description) = $_[1];
my (@dirs, $dir, $output, $path, $last, @descs, $desc);

@dirs = split (/\//, $input);
@descs = split (/\//, $description);
$last = pop (@dirs);
$last = pop (@descs);

$output = qq| <A HREF="$build_root_url/">Top</A> :|;
foreach $dir (@dirs) {
$path .= "/$dir";
$desc = shift (@descs);
$output .= qq| <A HREF="$build_root_url$path/">$desc</A> »|;
}
$output .= "<B> $last</B>";

return $output;
}



Everyone in the house is sick (bronchitis) or I would have been more helpful sooner...

For the css, you don't need those names I used, of course, and for a test just define a box to put each category in, like so:

.catbox {width: 250px; height: 100px;}

Hmm, 'catbox' might not be a good name...



This is an old post from Stealth, and tells how to use different build subs for man and category pages (edited for clarity). So, you can have two columns on the home page, and one on the rest (like my site). This was one of those things that took hours of searching to find, but is so simple to do once found.


1) You will need to have two sub site_html_print_cat routines in the site_html_templates.pl or site_html.pl files depending if you are using templates. Copy the sub site_html_print_cat routine and name the new sub-routine sub site_html_print_subcat.

2) In this new sub-routine (sub site_html_print_subcat), delete the following codes:


--------------------------------------------------------------------------------
Code
--------------------------------------------------------------------------------


if ($i == $half) { $output .= qq|</td><td valign="top" width="50%">\n|; }

--------------------------------------------------------------------------------



3) Then in your sub build_category_pages routine in the nph-build.pl, replace &site_html_print_cat with &site_html_print_subcat.

4) Re-build your index/directory.


Leonard
aka PerlFlunkie

Last edited by:

PerlFlunkie: Mar 10, 2003, 1:49 PM
Quote Reply
Re: [Nightjar] Subcats count for table cells In reply to
If you want to change the look of the home and category pages: set up an IF statement to control the code for printing the cats/subcats based upon which page (home/category) is being printed. Now you see why I suggested two separate routines - one for the home.html page and a separate one for the category.html page.
it looks like

Code:
if ($half==1) {
# this is for the HOME.HTML page
# 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 links)</small> |;
$output .= qq|<small><sup class="new">&nbsp;new&nbsp;</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|<dd><span class="descript">$subcats</span></dd>|;
$output .= qq|</dl>|;
}
else {
# this is for the CATEGORY.HTML (subcats page)page(s)
# 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 links)</small> |;
$output .= qq|<small><sup class="new">&nbsp;new&nbsp;</sup></small>| if (&days_old($mod) < $db_new_cutoff);
$output .= qq|</dt>|;
$output .= qq|<dd><span class="link">catlink </span></dd>| if (!($description =~ /^[\s\n]*$/));
$output .= qq|<dd><span class="catlink">$subcats</span></dd>|;
$output .= qq|</dl>|;
}

You will need to create a new item in you links.css and change to suit your needs.

SPAN.catlink {
FONT-SIZE: 12px; BACKGROUND: none transparent scroll repeat 0% 0%; COLOR: #333333; FONT-FAMILY: "Trebuchet MS", "Lucida Grande", Verdana, sans-serif


or you could do the following

Code:
# this is for the HOME.HTML page
# 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 links)</small> |;
$output .= qq|<small><sup class="new">&nbsp;new&nbsp;</sup></small>| if (&days_old($mod) < $db_new_cutoff);
$output .= qq|</dt>|;
if ($half==6) {
$output .= qq|<dd><span class="descript">$description </span></dd>| if (!($description =~ /^[\s\n]*$/));
$output .= qq|<dd><span class="descript">$subcats</span></dd>|;
$output .= qq|</dl>|;
}
# this is for the CATEGORY.HTML (subcats page)page(s)
else {

$output .= qq|<dd><span class="link">catlink </span></dd>| if (!($description =~ /^[\s\n]*$/));
$output .= qq|<dd><span class="catlink">$subcats</span></dd>|;
} $output .= qq|</dl>|;


Gene
"The older I get, the more I admire competence, just simple competence in any field from adultery to zoology."

Last edited by:

esm: Mar 11, 2003, 11:16 AM