Gossamer Forum
Home : Products : Links 2.0 : Customization :

Split Links output into two columns

Quote Reply
Split Links output into two columns
Hi there. Can someone please help me out here. I'm wondering what code I would insert into site_html_link so that I can split the output of it into two columns - just like what the script does with categories.

I hope that makes sense. Smile

Thanks, your help would be greatly appreciated!

Henry
Quote Reply
Re: Split Links output into two columns In reply to
go to this thread:

www.gossamer-threads.com/scripts/forum/resources/Forum3/HTML/003206.html

i haven't found any bugs for this... yet.

this is for templates only... i made the mod to put banners in, but u could easily put a </td><td> in its place.

[This message has been edited by garadon (edited September 28, 1999).]
Quote Reply
Re: Split Links output into two columns In reply to
Hi! Thanks for the reply. Unfortunately, I'm not using the templates, so does anyone know how to do this without templates?

Thanks!

Henry
Quote Reply
Re: Split Links output into two columns In reply to
uhh...

something like this:

you find something along the lines of:

Code:
for ($i = 0; $i < $build_links_per_page; $i++) {
%tmp = &array_to_hash ($i, @{$links{$cat}});
$links .= &site_html_link (%tmp);
}

in nph-build.cgi build_catgory_pages..

then you change it with:

Code:
for ($i = 0; $i < $build_links_per_page; $i++) {
%tmp = &array_to_hash ($i, @{$links{$cat}});
$links .= &site_html_link (%tmp) if ($i <= int{$#links/2));
$links2 .= &site_html_link (%tmp) if ($i > int{$#links/2));
}

it's sorta messy code.. but it will do.. Smile

you have to add

Code:
link2 => $links2,

to the category template i hope you know..

and the only other thing i can tell you is you might have to add the scalar $links2 into the "local" section on the top of the routine to avoid other categories links appearing on categories with 1 link.. (meaning it won't make a second row..)

btw.. the above code may not match exactly with your nph-build.cgi.. there also might be 2 parts that you will need to modify.. i think there might be one that looks like this:

Code:
for ($i = 0; $i < $#{$links{$cat}}; $i++) {
%tmp = &array_to_hash ($i, @{$links{$cat}});
$links .= &site_html_link (%tmp);
}

just change the $links line into the two lines..

jerry
Quote Reply
Re: Split Links output into two columns In reply to
OHH... you're not using templates.. hhehe


just put $links2 on the part of the site_html_category page you want it to be

jerry
Quote Reply
Re: Split Links output into two columns In reply to
Grrr... that looks suspiciously like code that i experimented with but gave me lotsa bugs... ah... i see what i did wrong... doh!

wait a minute... hey, widgetz, shouldn't this
Code:
for ($i = 0; $i < $build_links_per_page; $i++) {
%tmp = &array_to_hash ($i, @{$links{$cat}});
$links .= &site_html_link (%tmp) if ($i <= int{$#links/2));
$links2 .= &site_html_link (%tmp) if ($i > int{$#links/2));
}

be this?

Code:
for ($i = 0; $i < $build_links_per_page; $i++) {
%tmp = &array_to_hash ($i, @{$links{$cat}});
$links .= &site_html_link (%tmp) if ($i <= int($#links/2));
$links2 .= &site_html_link (%tmp) if ($i > int($#links/2));
}

I can always see those problems in other people's code... just never my own...

[This message has been edited by garadon (edited September 28, 1999).]
Quote Reply
Re: Split Links output into two columns In reply to
oh.. hehe Smile

i told you i never test anything.. anyways..

yea.. that's right

jerry
Quote Reply
Re: Split Links output into two columns In reply to
Hi there. Thanks for all of your help. I have followed all of your instructions, but unfortunately am still having no luck. It does not appear to be inserting </tr><tr> between the two different links.

So, if I have three links, it is still coming out in this format...

LINK1 LINK2 LINK3

instead of

LINK1 LINK2
LINK3

Do you have any other suggestions as to what the problem might be? I have checked to make sure that I have done everything you said in your previous postings.

Thank you.

Henry
Quote Reply
Re: Split Links output into two columns In reply to
of course it doesn't add the </tr><tr>

you have to do it yourself..

like

$links
</tr><tr>
$links2

anyways..

jerry
Quote Reply
Re: Split Links output into two columns In reply to
Hi! Thanks for the reply. Yes, I have tr tags there, but it is not working...

Here is what I have in the category code...

if ($links) {$output .= qq~
<tr>
$links
$links2
</tr>~;
}


Here is the code that I have put in site_html_link just to try and see if it works...
$output = qq~<td width="50%"><strong>HELLO!!!!!!</strong></td>~;


Thanks, hopefully you will be able to see what I am doing wrong.

Best,

Henry
Quote Reply
Re: Split Links output into two columns In reply to
and where did that HELLO!! line come from??

jerry
Quote Reply
Re: Split Links output into two columns In reply to
Hi there,
The hello code is just there to test it. I did that instead of designing the entire layout, just until I got this links column thing working. Basically, for each link on a page, it will print hello. I will obviously change this as soon as I get this working.

I hope that makes sense. Smile

Best,

Henry
Quote Reply
Re: Split Links output into two columns In reply to
Hi again...
I was just playing around with this mod a bit and I changed this line...

$links2 .= &site_html_link (%tmp) if ($i > int($#links/2));

to this...

$links2 .= &site_html_two (%tmp) if ($i > int($#links/2));

and then I created this sub routine in site_html.pl. So, I now have these two lines in nph-build.cgi...

$links .= &site_html_link (%tmp) if ($i <= int($#links/2));
$links2 .= &site_html_two (%tmp) if ($i > int($#links/2));

In the sub routine I changed that hello to something else and then built the pages again. When i went to one of the pages with a few links on it, it was only printing the "HELLO!" one which is the &site_html_link which means that it is not doing anything with $links2.

Just thought you should know...

Henry
Quote Reply
Re: Split Links output into two columns In reply to
hehe.. did i ever mention...

$#links

should be:

$#{$links{$cat}}

not sure if that is the right way.. (cause my script is modded everywhere) but i think it might be..

jerry
Quote Reply
Re: Split Links output into two columns In reply to
Hi again,
Sorry to keep asking you questions about this. I have made those changes you told me to, but it does still not appear to be working. Below is a copy of my build_category_pages. I thought it might help you figure out what is going wrong...

Code:
sub build_category_pages {
# --------------------------------------------------------
# This routine builds all the category pages. Each category uses
# the same template which is defined in &site_html_category.

# Modified June 26, 1999
# Fixing the bug of Prev

my ($cat, $url, $dir, @related, $relation, $page_num, $prev_page, $next_page, $numlinks);
local ($category, $links, $links2, $title_linked, $title, $total, $category_name, $category_name_escaped);
local ($description, $related, $meta_name, $meta_keywords, $header, $footer, $next, $prev);

# Go through each category and build the appropriate page.
CATEGORY: foreach $cat (sort keys %category) {
next CATEGORY if ($cat =~ /^\s*$/); # How'd that get in here? =)

$url = "$build_root_url/" . &urlencode($cat) . "/";
$use_html ?
print qq|Building Category: <A HREF="$url" TARGET="_blank">$cat</A>\n| :
print qq|Building Category: $cat\n|;
print "\tSubcategories: " . ($#{$subcategories{$cat}} + 1) . "\n";
print "\tLinks: " . (($#{$links{$cat}}+1) / ($#db_cols+1)) . "\n";

# Let's make sure the directory exists, build it if it doesn't.
$dir = &build_dir ($cat);
print "\tDirectory: $dir\n";
print "\tFilename : $dir/$build_index\n";

# We set up all the variables people can use in &site_html.pl.
($description, $related, $meta_name, $meta_keywords, $header, $footer) = @{$category{$cat}}[2..7];

# Calculate the related entries and put in a <LI> list.
@related = split(/\Q$db_delim\E/, $related); $related = "";
foreach $relation (@related) {
$related .= qq|<li><a href="$build_root_url/|;
$related .= &urlencode($relation);
$related .= qq|/$build_index">|;
$related .= &build_clean($relation);
$related .= "</a> ($stats{$relation}[0])</li>";
### mod Frown$stats{$relation}[0]) added to display number of related links
}

# Get the header and footer from file if it exists, otherwise assume it is html.
if ($header && (length($header) < 20) && ($header !~ /\s+/) && (-e "$db_header_path/$header")) {
open (HEAD, "<$db_header_path/$header") or &cgierr ("Unable to open header file: $db_header_path/$header. Reason: $!");
$header = "";
while (<HEAD> ) {
$header .= $_;
}
close HEAD;
}
if ($footer && (length($footer) < 20) && ($footer !~ /\s+/) && (-e "$db_footer_path/$footer")) {
open (FOOT, "<$db_footer_path/$footer") or &cgierr ("Unable to open footer file: $db_footer_path/$footer. Reason: $!");
$footer = "";
while (<FOOT> ) {
$footer .= $_;
}
close FOOT;
}
$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);

# Store all the category html info in $category.
if ($#{$subcategories{$cat}} >= 0) {
$category = &site_html_print_cat (@{$subcategories{$cat}});
}
else {
$category = "";
}

$numlinks = ($#{$links{$cat}} + 1) / ($#db_cols + 1);
$next = $prev = $links = "";
if (($numlinks > $build_links_per_page) && $build_span_pages) {
$total_pages=(int($numlinks/$build_links_per_page)); #added
if ($total_pages < $numlinks/$build_links_per_page) {$total_pages++}
$next .= "<b>1</b>"; # new added
for $j(2..($total_pages)){ #added & changed
$next .= qq~ <a href="more$j$build_extension">$j</a>~; #added
} # end of for #added

$page_num = 2;

$next .= qq~ <a href="more$page_num$build_extension">[Next >>]</a>~; #added
for ($i = 0; $i < $build_links_per_page; $i++) {
%tmp = &array_to_hash ($i, @{$links{$cat}});
$links .= &site_html_link (%tmp) if ($i <= int($#{$links{$cat}}/2));
$links2 .= &site_html_two (%tmp) if ($i > int($#{$links{$cat}}/2));
}
@{$links{$cat}} = @{$links{$cat}}[(($#db_cols+1)*$build_links_per_page) .. $#{$links{$cat}}];
$numlinks = ($#{$links{$cat}}+1) / ($#db_cols + 1);
}
# Otherwise we either only have less then x number of links, or we are not
# splitting pages, so let's just build them all.
else {
for ($i = 0; $i < $numlinks; $i++) {
%tmp = &array_to_hash ($i, @{$links{$cat}});
####$links .= &site_html_link (%tmp);
####$links .= &site_html_link (%tmp) if ($i <= int($#links/2));
$links .= &site_html_link (%tmp) if ($i <= int($#{$links{$cat}}/2));
$links2 .= &site_html_two (%tmp) if ($i > int($#{$links{$cat}}/2));
}
}
# Create the main page.
open (CAT, ">$dir/$build_index") or &cgierr ("unable to open category page: $dir/$build_index. Reason: $!");
print CAT &site_html_category;
close CAT;
# Then we go through the list of links and build on the remaining pages.
while ($next && $build_span_pages) {

if ($numlinks > $build_links_per_page) {

$prev=$next=$next_page=$prev_page=""; #added
$next_page = $page_num+1;
$prev_page = $page_num-1; #added

if ($page_num == 2){
$prev .= qq~ <a href="$url">[<< Prev]</a> ~;
$prev .= qq~ <a href="$url"> 1</a> ~;}

else {$prev .= qq~ <a href="more$prev_page$build_extension">[<< Prev]</a> ~;
$prev .= qq~ <a href="$url">1</a> ~;
for $k(2..$prev_page){$prev .= qq~ <a href="more$k$build_extension">$k</a>~;}}

$next .= qq~ <b>$page_num</b> ~; #added

for $m($next_page..$total_pages){$next .= qq~ <a href="more$m$build_extension">$m</a>~;}

$next .= qq~ <a href="more$next_page$build_extension">[Next >>]</a>~; #added
} # end of if

else {
if ($page_num == $total_pages) {
$prev = $next = $next_page = $prev_page= "";
$prev_page=$total_pages-1;

if ($page_num == 2){
$prev .= qq~ <a href="$url">[<< Prev]</a> ~;
$prev .= qq~ <a href="$url"> 1</a> ~;}

else {$prev .= qq~ <a href="more$prev_page$build_extension">[<< Prev]</a> ~;
$prev .= qq~ <a href="$url">1</a> ~;
for $k(2..$prev_page){$prev .= qq~ <a href="more$k$build_extension">$k</a>~;}
} # end of else

$prev .= qq~ <b>$page_num</b> ~; #added
} # end of if
} # end of else

$links = "";
LINK: for ($i = 0; $i < $build_links_per_page; $i++) {
%tmp = &array_to_hash ($i, @{$links{$cat}});
last LINK if ($tmp{$db_key} eq "");
$links .= &site_html_link (%tmp) if ($i <= int($#{$links{$cat}}/2));
$links2 .= &site_html_two (%tmp) if ($i > int($#{$links{$cat}}/2));
}
$title_linked = &build_linked_title ("$cat/Page_$page_num/");
$title = &build_unlinked_title ("$cat/Page_$page_num/");

$use_html ?
print qq|\tSubpage : <A HREF="|, $url, qq|more$page_num$build_extension" TARGET="_blank">$dir/more$page_num$build_extension</A>\n| :
print qq|\tSubpage : $dir/more$page_num$build_extension\n|;

open (CAT, ">$dir/more$page_num$build_extension") or &cgierr ("unable to open category page: $dir/index$page_num$build_extension. Reason: $!");
print CAT &site_html_category;
close CAT;

@{$links{$cat}} = @{$links{$cat}}[(($#db_cols+1)*$build_links_per_page) .. $#{$links{$cat}}];
$numlinks = ($#{$links{$cat}}+1) / ($#db_cols + 1);

if ($page_num == $total_pages) { last; }
else { $page_num++; }

}
print "\n";
}
}

There is one thing that is different this time though. As I mentioned previously, I have $links2 now pointing to site_html_two which prints out something like BBBLO (just something different to HELLO). However, when I took $links2 out $site_html_category, it printed BBBLO, so somehow $links is pointing to $site_html_two. I hope that makes sense. Smile

Thanks - your help with this is greatly appreciated!

Best,

Henry
Quote Reply
Re: Split Links output into two columns In reply to
hmmm... I'm replying to yesterday's stuff... somewhere in your site_html.pl code (i use templates, so i'm not entirely sure where -- it's for whatever function builds the cat pages that you have $links and $links2), there should be this:
Code:
<table>
<tr>
<td>
$links
</td>
<td>
$links2
</td>
</tr>
</table>
u might already have this, but we didn't really make that clear...

--Tom

[This message has been edited by garadon (edited September 30, 1999).]
Quote Reply
Re: Split Links output into two columns In reply to
Hi Garadon, Yes, I had already done that, but unfortunately it is still not working. Smile

Best

Henry
Quote Reply
Re: Split Links output into two columns In reply to
What does that sub site_html_two do, exactly? did you copy sub site_html_link straight over? That might be doing it. Why don't u put the code up for that, and whatever function it is that actually builds the html.

also, jerry -- i had a similar error when i was attempting to use this method, which is why i gave it up... maybe we have bad code karma for not commenting enough...

--Tom

[This message has been edited by garadon (edited September 30, 1999).]
Quote Reply
Re: Split Links output into two columns In reply to
the code won't work flat out like that.. first of all.. you have to add 2 to $#{$links{$cat}} before dividing it by zero..

jerry
Quote Reply
Re: Split Links output into two columns In reply to
Hi Widgetz,
I'm sorry about this... I must seem so dumb, but I really don't understand what you mean by adding two to that statement before dividing it by 0.

Would you please be able to contact me on ICQ if you have it; my number is 8864803.

Thank you. I would really appreciate your help on this. I would be more than happy to consider some form of payment for your help or free advertising on findascript.com for your website.

Best, Henry

[This message has been edited by Henry (edited September 30, 1999).]