Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Adding a number in front links whne listing

Quote Reply
Adding a number in front links whne listing
Hello,

How do I add a number to the beginning of each link when I list every link in each category?

------------------
James L. Murray
PaintballCity.com
The Yahoo of Paintball
www.paintballcity.com
AIM: Paintball City
ICQ: 44147229





Quote Reply
Re: Adding a number in front links whne listing In reply to
Hello PugDog,

Where do I do this. I looked in HTML_Templates.pm and I found the sub html_print_cat routine. I did not find a 'while' loop or the &get_link part you were talking about.

Can you post your email address I want to ask you about some custom work for me.

------------------
James L. Murray
PaintballCity.com
The Yahoo of Paintball
www.paintballcity.com
AIM: Paintball City
ICQ: 44147229







[This message has been edited by Ground Zero (edited April 11, 2000).]
Quote Reply
Re: Adding a number in front links whne listing In reply to
What you could do is in site_html_link (this would break under mod_perl, and isn't that elegant, but..) add:

LinkNum => $counter{$tags->{CategoryID}}

to the list of tags that get passed. Then you need to add:

use vars qw/%counter/;

to the top of the script.

Another way to do it (probably better) is to use numbered lists in html using <ol> </ol> etc. This is quite easy. Only downside is that if you have multiple spanning pages, the numbers would reset each time.

Cheers,

Alex
Quote Reply
Re: Adding a number in front links whne listing In reply to
In the print_cat routine, there is a loop that prints out the links, and then figures out to span pages.

Just set a variable before you enter the output process:

my $LinkCount = 0;

Then, at the top of the 'while' loop, increment it:

$LinkCount = $LinkCount +1;

And, when you make the call to &get_link, you need to add

"LinkCount => $LinkCount"

To the passed HASH.

This will make <%LinkCount%> available in the link.html template, and it will be different for each link.

Quote Reply
Re: Adding a number in front links whne listing In reply to
I don't think I meant the print_cat routine.

I think I meant the sub site_html_category routine.

Check out:

http://www.postcards.com/...ostcards/pages/Cool/

This should be the same idea, but I haven't checked it on any page but the 'cool' one.

Quote Reply
Re: Adding a number in front links whne listing In reply to
Hello,

I don't see a while statement in the sub site_html_category. Here is what I tried:
Code:
sub site_html_category {
# --------------------------------------------------------
# This rountine will build a page based for the current category.
#
my $LinkCount = 0;
$LinkCount = $LinkCount +1;


my ($tags, $dynamic) = @_;
my $template = defined $dynamic ? $dynamic->param('t') : undef;
(ref $tags eq 'HASH') or croak "HTML_TEMPLATES: Argument '$tags' must be hash reference";

my ($name) = $tags->{'category_name'} =~ m,/?([^/]+)$,;
defined $dynamic and &load_user ($dynamic, $tags);
my $output = &load_template ( 'category.html', {
%$tags,
LinkCount => $LinkCount,
build_links_per_page => $LINKS{build_links_per_page},
category_first => $name,
%GLOBALS
}, undef, $template );
defined $dynamic and &clean_output($dynamic, \$output);
return $output;
}

What do I do?

------------------
James L. Murray
PaintballCity.com
The Yahoo of Paintball
www.paintballcity.com
AIM: Paintball City
ICQ: 44147229





Quote Reply
Re: Adding a number in front links whne listing In reply to
Let's not make this harder than it is. (first, lets get the right subroutine <G> )

We are looking at sub build_category_pages in nph_build.cgi where the links are built for the pages.

The logic is, to initialize the variable, then pass it as a value in each link JUST BEFORE it goes to the link template.

So, define

my $links_count = '0';

at the top of sub build_category_pages in nph_build.cgi.

Then, later down, where you see:

Code:
# If we are spanning pages, we grab the first x number of links and build
# the main index page. We set $numlinks to the remaining links, and we remove
# the links from the list.

initialize the variable. This is just before any of the loops, tests, and checks for links, but AFTER you know what category you are working in.

$links_count=0;


Then, in 3 places, you want to change:

Code:
$tmp = $LINKDB->array_to_hash (${$links_r}[$i]);
$OUT{links} .= &site_html_link ($tmp);

to

Code:
$tmp = $LINKDB->array_to_hash (${$links_r}[$i]);
$links_count= $links_count+1;
$tmp->{'links_count'}=$links_count;
$OUT{links} .= &site_html_link ($tmp);


This increments the link number FIRST, then assigns it to the temporary link hash, which is passed BY REFERENCE to the site_html_link building routine.

The tag <%links_count%> is now available in the link.html template.


BTW: if you want to see what it does:

www.postcards.com/DP_Test/pages/

This is my test site, so you never know what to expect, and it's often not pretty... but I added:

Code:
<P><FONT FACE=ARIAL SIZE=3><B>This is Link #<%links_count%></B></FONT></P>

to the link for testing purposes.



[This message has been edited by pugdog (edited April 12, 2000).]
Quote Reply
Re: Adding a number in front links whne listing In reply to
See how hard it was to get the right sub category?? It was the hardest part of the whole job <G> I edited the post to cut the confusion. That's what happens when I work so late at night.

[This message has been edited by pugdog (edited April 12, 2000).]
Quote Reply
Re: Adding a number in front links whne listing In reply to
Hello PugDog,

Worked like a charm. Thanks.

It was actually sub build_category_pages in nph_build.cgi

Thanks again.

------------------
James L. Murray
PaintballCity.com
The Yahoo of Paintball
www.paintballcity.com
AIM: Paintball City
ICQ: 44147229





Quote Reply
Re: Adding a number in front links whne listing In reply to
How can I do this for search.cgi? Can you point me in the right direction?

Thanks.

------------------
James L. Murray
PaintballCity.com
The Yahoo of Paintball
www.paintballcity.com
AIM: Paintball City







Quote Reply
Re: Adding a number in front links whne listing In reply to
Code:
# Build the list of link results.
if ($link_hits) {
my (%link_results, %displayed, $name);
foreach my $hit (@$link_hits) {
$hit = $linkdb->array_to_hash ($hit);
$link_results{$hit->{CategoryID}} .= &site_html_link ($hit, $dynamic);
}
foreach my $hit (@$link_hits) {
next if ($displayed{$hit->{CategoryID}}++);
$name = &get_category_name ($hit->{CategoryID});
$link_results .= "<p>" . &search_build_linked_title ($name) . "</p>";
$link_results .= $link_results{$hit->{CategoryID}};
}
}

You'd want to initialize the counter:

my $links_count=0;

before the above block of code, then increment it right after the following line:

$hit = $linkdb->array_to_hash ($hit);

and pass a new value into the $hit hash:

$hit->{'links_count'} = $links_count;

you might be able to do something like:

$hit->{'links_count'} = $links_count+1;

and keep it all in one line, not two.

Should be the idea, I don't have time to play with it, please post your results!







------------------
POSTCARDS.COM -- Everything Postcards on the Internet www.postcards.com
LinkSQL FAQ: www.postcards.com/FAQ/LinkSQL/








Quote Reply
Re: Adding a number in front links whne listing In reply to
Psuedo random is more like it....

Before I tell you what is happening, look at the output and see if you can figure it out.

Meanwhile, I'll look at the code and see why it's doing that... it should be a small fix.

Learning to see the output correctly is a _real_ skill you need to develop. Looking at the output should have told you immediately what was happening. Smile You've been digging into the code enough to see it.

Are the numbers really random, or is there a pattern/logic to what's going on?



Quote Reply
Re: Adding a number in front links whne listing In reply to
The danger of typing when tired:

Try:

$hit->{'links_count'} = ++$links_count;

What was happening is that $links_count was never actually being incremented. It was always '0'


[This message has been edited by pugdog (edited April 14, 2000).]
Quote Reply
Re: Adding a number in front links whne listing In reply to
Hello Pugdog,

I have installed the new line of code. It is numbering the search results in random. Check it out at: http://www.medinfolinks.com/....cgi?query=Pregnancy

Any idea why?

P.S. Thanks for your help.

------------------
James L. Murray
PaintballCity.com
The Yahoo of Paintball
www.paintballcity.com
AIM: Paintball City









[This message has been edited by Ground Zero (edited April 14, 2000).]
Quote Reply
Re: Adding a number in front links whne listing In reply to
Hello,

Well it almost worked. I have it saying 1 for every search result. Check out the search results page at http://www.medinfolinks.com/....cgi?query=Pregnancy

The code I used in search.cgi is below:
Code:
my $links_count=0;
# Build the list of link results.
if ($link_hits) {
my (%link_results, %displayed, $name);
foreach my $hit (@$link_hits) {
$hit = $linkdb->array_to_hash ($hit);
$hit->{'links_count'} = $links_count+1;

$link_results{$hit->{CategoryID}} .= &site_html_link ($hit, $dynamic);
}
foreach my $hit (@$link_hits) {
next if ($displayed{$hit->{CategoryID}}++);
$name = &get_category_name ($hit->{CategoryID});
$link_results .= "<P>" . &search_build_linked_title ($name) . "<BR>";
$link_results .= $link_results{$hit->{CategoryID}};
}
}

Any ideas on how to get it to increment?


------------------
James L. Murray
PaintballCity.com
The Yahoo of Paintball
www.paintballcity.com
AIM: Paintball City







Quote Reply
Re: Adding a number in front links whne listing In reply to
Right...I noticed that pattern also...I will try to figure it out.
Quote Reply
Re: Adding a number in front links whne listing In reply to
It's my #1 peeve about Links... is the way it tries to sort everything into categories.

What's happening, is the links are being pulled, formatted, then sorted into categories.

They need to be pulled, sorted _then_ put into categories.

I haven't had a chance to look at the code, but I'll bet it's doing something like putting (using .=) the link into a hash based on the category ID, then printing out the categories at the end. The links would be in order based on whatever sort criteria was used on the hash.

This process needs to be broken down into two steps, not one.

First, get all the "hits" then, sort the links into the categories, _THEN_ format each group of links by category.

I didn't notice this since I cut out the category sorts from most of my displays, since it's only relavent on my sites for browsing, not searches.




Quote Reply
Re: Adding a number in front links whne listing In reply to
Thanks, pugdog, for the codes. I was able to translate them into LINKS 2.0.

I am working on the number results for the search script, and I will post the codes in SQL when I get a chance...to assist those who still have category sorting.

Regards,


------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.
Quote Reply
Re: Adding a number in front links whne listing In reply to
Great! The more the merrier Smile

I just can't go back to flat-files... I would feel pain trying to go through the 2.0 code -- even the code I started the sites with. Kudos for making it work retrograde! I always wanted a better way to handle files and databases through the years, and now that I've found it, I'm addicted Smile

I've been a fan of OOP since I first read about it (since I've always hated spaghetti code) and I hate re-inventing the wheel! Objects allow reuse and if you need a new feature, just improve or update the object, don't re-write it! Between SQL (MySQL) and OOP PERL/mod_perl I'm having a lot of fun programming again for the first time in 10+ years. It doesn't hurt that it's on a non-M$ operating system either <G>!!!


Quote Reply
Re: Adding a number in front links whne listing In reply to
Thanks...(Not that hard if you understand anything about hashes).

I will post the codes in SQL and regular Perl, so that both SQL and LINKS 2.0 users can use the codes...I know that LINKS 2.0 users have requested this for the search results...and I, too, like the numbers next to links.

Wink

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
Anthro TECH, L.L.C
anthrotech.com
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.


Quote Reply
Re: Adding a number in front links whne listing In reply to
BTW... it wasn't clear in the postings, but you'd need to change the build_cool and build_new as well as search.cgi, if you want to use the same links template for everyting.

The way around it is to use:

Code:
<%if links_count%>
<FONT FACE=ARIAL SIZE=3><B>Link #<%links_count%>: </B></FONT>
<%endif%>

What that will do is in any routine where a number is passed, it will be used, and where it's not, you won't see the "unknown tag" error message.

You can then use the same template, and update your routines one by one.

Quote Reply
Re: Adding a number in front links whne listing In reply to
Just read this thread and checked out the example of the random link number problem when using it in search.cgi

Did anyone work out how do fix this problem so that the search results are also numbered correctly? If yes then please could you copy and paste the correct code below.

Thanks

Quote Reply
Re: Adding a number in front links whne listing In reply to
 
The "fix" again would be to break the process down into two steps. First, find all the links, and put the references into a hash of reference by category.

Then, sort the hash by category, (sort key) and pull each link reference out, THEN send it to link.html along with a number, and add that to the $OUTPUT variable one at a time.

What is being done now, is the link is being taken from the databse, turned into an HTML nugget, then put into a hash by category, which is then flattened into the larger output variable by adding each "category" of links as a chunk.

You have to break that into discreete steps, in order to number the output, and add the links to $OUTPUT one at a time.

http://www.postcards.com
FAQ: http://www.postcards.com/FAQ/LinkSQL/

Quote Reply
Re: Adding a number in front links whne listing In reply to
What do you need to change to stop this mod from displaying a random link number in search.cgi? I noticed GroundZero's site was still showing random link numbers in the search results.


# Build the list of link results.
if ($link_hits) {
my (%link_results, %displayed, $name);
foreach my $hit (@$link_hits) {
$hit = $linkdb->array_to_hash ($hit);
$link_results{$hit->{CategoryID}} .= &site_html_link ($hit, $dynamic);
}
foreach my $hit (@$link_hits) {
next if ($displayed{$hit->{CategoryID}}++);
$name = &get_category_name ($hit->{CategoryID});
$link_results .= "<p>" . &search_build_linked_title ($name) . "</p>";
$link_results .= $link_results{$hit->{CategoryID}};
}


JeffB
Quote Reply
Re: Adding a number in front links whne listing In reply to
Done it myself (at last :-) )

Quote Reply
Re: Adding a number in front links whne listing In reply to
What did you do, jeffb?

Thanks