Gossamer Forum
Home : Products : Links 2.0 : Customization :

How to add new links to front page?

(Page 1 of 2)
> >
Quote Reply
How to add new links to front page?
Hi;
Can anyone help me how to add the new links have been added to the database to the front page which is index.html? It has to do with <%link_results%>
Quote Reply
Re: How to add new links to front page? In reply to
There's a lastlink mod in the resource centre. I haven't looked at the code but you can probably easily modify it to display more than one link.

------------------
-----------------
Lavon Russell
LookHard! Search
http://lh.hypermart.net
webmaster@lh.hypermart.net



Quote Reply
Re: How to add new links to front page? In reply to
Tyhe current LastLink mod only takes the most recently added link and put it on the homepage. Widgetz has helped me with another mod which takes the last 5 links - I'll publish that if Widgetz gives his permisson.

But it sounds more like what you are asking for is how to use the What's New page as the homepage. Or?? (I don't understand what you mean: 'It has to do with <%link_results%>').

John
Quote Reply
Re: How to add new links to front page? In reply to
What I meant is that I want to display the new links added in today in the frontpage where the main categories are. How do I do that? and how do I display the coolest links in the front apge tooo? Just the links but not the descriptions. Anyhelp, please.
Quote Reply
Re: How to add new links to front page? In reply to
I'm also interested in this kind of thing,
but instead of todays, I would like.. say the last 10 or last 8 or so.

I've looked at last link, and I'm afraid I've tried everything I can to get it to loop 5 or more times to produce the results I need and it seems my perl skills fall short Smile Anyone have this already done and could help us out?

------------------
The Crowe crowe@charter.net
www.lit.org Links Engine for Writing on the net!



Quote Reply
Re: How to add new links to front page? In reply to
Here is a Last Five Links mod to the Last Link mod. Widgetz has done it. I can't get it to work :-( and Widgetz is busy with his school. So I relaease it here in the hope of someone being able to get it to work ...

Code:
open (DB, "<$db_file_name") or &cgierr("unable to open database:
$db_file_name.\nReason: $!");
LINE: while (<DB> ) {
(/^$/) and next LINE;
(/^#/) and next LINE;
chomp;
@data = &split_decode($_);
push (@lastlink, @data);
}
close DB;

my $j = int($#lastlink/$#db_cols)-1;

for ($i = $j; $i > $j-5; $i--) {
%tmp = &array_to_hash ($i, @lastlink);
$lastlink .= qq~$tmp{'Title'}<br>\n~;
}

The code replaces the code in the nph-build.cgi part of Last links.

Widgetz also said:
If you get errors.. try changing:

my ($subcat, @rootcat);
local ($total);

to:

my ($subcat, @rootcat, @lastlink);
local ($total, $lastlink);

(I don't get errors, just plain nothing ... also when trying this code).

Let me and Widgetz know if you get it to work.

John
Quote Reply
Re: How to add new links to front page? In reply to
I think this is a great mod and is better than just the Last Link mod... Anyway, I didn't get it to work, too. In site_html_template.pl at the html for the homepage I added a new field called

LastLink => $lastlink,

but when I include <%LastLink%> in home.html and re-build the sites I can't see anything!!! I didn't get an error... Widgetz, could you please help me??!!

THANX!!!
Quote Reply
Re: How to add new links to front page? In reply to
How about something like:

Code:
my $LASTX = 5;

open (DB, "<$db_file_name") or &cgierr("unable to open database:$db_file_name.\nReason: $!");
my @lines = <DB>;
close DB;

for my $i ($#lines - $LASTX .. $#lines) {
chomp $lines[$i];
@tmp = &split_decode ($lines[$i]);
%tmp = &array_to_hash (0, @tmp);
$lastlink .= &site_html_link (%tmp);
}

This will take the whole database into @lines, then go over the last 5 entries and store the HTML in $lastlink. You then need to make sure you add lastlink => $lastlink in site_html_home.

Note: I made a mistake in the first posting, but the above looks better.

Hope this helps,

Alex

[This message has been edited by Alex (edited September 08, 1999).]
Quote Reply
Re: How to add new links to front page? In reply to
alex you smarty pants Smile

hehe.. the way i did it was totally different than that code.. i wanted to include the updated.. so i ended up pushing the new_links and the updated_links (i added that) hashes to get them.. and then sorted by the modified date.. although this isn't the best... (cause a link modified on the same date might not be first).. i find it good enough..

anyways.. i'm having problems with my science.. put this in order... Smile

evolution, big bang, earth, plate tectonics, change, rock cycle, fossil records, genetics, universe, earthquakes, natural selection, survival, evidence, weathering..

yea Smile

jerry
Quote Reply
Re: How to add new links to front page? In reply to
I am sorry that I don't understand where do you put the code:
my $LASTX = 5;
...
...
&site_html_link (%tmp);
}
?What file and what part of it?
Quote Reply
Re: How to add new links to front page? In reply to
Well, I have not tried Alex code yet. May be I am afraid. Anyway, If you take a look at this website http://www.vietvision.com you will see how the new links on the frontpage and rating links on the frontpage. I don't know how they did it, but if you know how they did it. Please share you thoughts.
Thanks.
Quote Reply
Re: How to add new links to front page? In reply to
I tried Alex code, and it did not work. I put <%LastLink%> in the home.html. Then I got unknown tag: LaskLink.
Is there anything wrong with it Alex?
Quote Reply
Re: How to add new links to front page? In reply to
Try

lastlink => $lastlink

in the site_html_link routine.

Then in the home.html routine, try adding

<%lastlink%>

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: How to add new links to front page? In reply to
I didn't check out Alex' code yet, but if you get an unknown tag error you didn't put this

LastLink => $lastlink,

in site_html_templates.pl!

Try to replace this part in site_html_templates.pl

sub site_html_home {
# --------------------------------------------------------
# This routine will build a home page. It is not meant to have any
# links on it, only subcategories.

return &load_template ('home.html', {
category => $category,
grand_total => $grand_total,
%globals
});
}

with this code:

sub site_html_home {
# --------------------------------------------------------
# This routine will build a home page. It is not meant to have any
# links on it, only subcategories.

return &load_template ('home.html', {
category => $category,
grand_total => $grand_total,
LastLink => $lastlink,
%globals
});
}


Quote Reply
Re: How to add new links to front page? In reply to
The code Alex suggests replaces the code from the Last Link mod (see the resuorce centre). It goes in nph-build.cgi in the sub build_home_page just after
print "\tOpening page: $build_root_path/$build_index\n";

Well, I tried your code Alex, and I'm sorry to say that this code does not work for me either .... I tried it in two of my Links projects. In one, I get Unkown Tag: URLUnkown Tag: URLUnkown Tag: URLUnkown Tag: URLUnkown Tag: URLUnkown Tag: URL
(note it's there SIX times, not five). I use standard field codes in this version.

In my other installation, I get six links for 'more' (correct according to my design), but no descrition, and in the links, the whole database line with pipes and all is there instead of the ID.html ....

Oh well ... did you test your code Alex? I'm sure I am doing something stupid here, but I just can't see what Frown

John
Quote Reply
Re: How to add new links to front page? In reply to
Thanks for fixing the error Alex! (edited post today)

Now, it works. Well, sort of ...

1. It shows the _6_ most recent additions. Not a big problem (guess changing 5 to 4 in my $LASTX = 5; will fix this).

2. The order of the 6 links is like 376, 377, 378, ... Is it possible to have reverse order, so the most recent link shows on top?

Cheers
John
Quote Reply
Re: How to add new links to front page? In reply to
change:

for my $i ($#lines - $LASTX .. $#lines) {

to

for my $i ($#lines .. $#lines - $LASTX) {

and to fix that 5 to 4 thingy... change it to:

for my $i ($#lines .. $#lines - ($LASTX-1)) {
Quote Reply
Re: How to add new links to front page? In reply to
This mod is one of the most picky ones I've worked with ...
Widgetz, $#lines .. $#lines - $LASTX doesn't work Frown
When using it, I get five <BR>s and nothing else ...

[This message has been edited by gotze (edited September 09, 1999).]
Quote Reply
Re: How to add new links to front page? In reply to
Sorry again; I am completely off track now guys. PLease help me back in track. Canany willing to tell me in details how to make it works now? Here is what I did:
1) I opened nph_build.cgi then add Alex's code in as below:
Quote:
sub build_home_page {
# --------------------------------------------------------
my ($subcat, @rootcat);
local ($total);

# Check to see which categories are off of the root.
foreach $subcat (sort keys %category) {
if ($subcat =~ m,^([^/]*)$,) {
push (@rootcat, $subcat);
}
}
print "\tSubcategories: "; print $#rootcat+1; print "\n";
print "\tTotal Links: $grand_total\n";
print "\tOpening page: $build_root_path/$build_index\n";
my $LASTX = 5;
open (DB, "<$db_file_name") or &cgierr("unable to open database:$db_file_name.\nReason: $!");
my @lines = <DB>;
close DB;
for my $i ($#lines - $LASTX .. $#lines) {
chomp $lines[$i];
@tmp = &split_decode ($lines[$i]);
%tmp = &array_to_hash (0, @tmp);
$lastlink .= &site_html_link (%tmp);
}

open (HOME, ">$build_root_path/$build_index") or &cgierr ("unable to open home page: $build_root_path/$build_index. Reason: $!");
$category = &site_html_print_cat (@rootcat) if ($#rootcat >= 0);
$total = $grand_total;
print HOME &site_html_home;
close HOME;
print "\tClosing page.\n";
}
2) Then I open site_html_tamplates.pl and added the folowing to the site_html_home routine
Quote:
sub site_html_home {
# --------------------------------------------------------
# This routine will build a home page. It is not meant to have any
# links on it, only subcategories.

return &load_template ('home.html', {
category => $category,
grand_total => $grand_total,
lastLink => $lastlink,
%globals
});
}
3) The I added <%$lastlink%> to the home.html in template.

4) I build the site. anr open the page I got Unknowtag: lastlink.

What's wrong with that? Please help me.

[This message has been edited by tim (edited September 09, 1999).]
Quote Reply
Re: How to add new links to front page? In reply to
Nice mod!!! As for the reverse order, subsistute this
Code:
for ($i=$#lines; $i>=$#lines - $LASTX; $i--) {
for this...
Code:
for my $i ($#lines - $LASTX .. $#lines) {

And to embilish on the original concept,

1. create a new template called home_link.html, copying the original link.html if you wish.

2. change the following line in nph-build.cgi
Code:
$lastlink .= &site_html_home_link (%tmp);

3. copy your site_html_link subroutine in site_html_template.pl, rename it site_html_home_link, and change the line that loads the template to
Code:
return &load_template ('home_link.html', {

This will enable your links on the home page to look different from the category pages.
Quote Reply
Re: How to add new links to front page? In reply to
How about another approach all together? nph-build.cgi already takes care of building one HTML page per day which contains the new links for that day. Why not just use SSI to include that page on your front page?

You would also want to edit the template "new.html" to strip out everything but the new links. In the home.html template insert an SSI call to include http://www.yoursite.com/pages/new/<%date%>.html

I haven't actually done this, it's something I just thought of. I will try to implement it soon, though, and let you know how it works. It seems like a much simpler approach than the ones suggested so far. Comments anyone?
Quote Reply
Re: How to add new links to front page? In reply to
Thanks for all the help. I have written up instructions for LastLink 1.99, which now works for X links, showing them in reverse order (thanks oldmoney!). The instructions are at http://www.gotzespace.dk/books/linksmod/
(same link as the old LastLink, so the resource centre link is still valid).

If someone can fix the problem where X becomes X+1, let me know, and I'll write up instructions for LastLink 2.0 Smile

John

[This message has been edited by gotze (edited September 09, 1999).]
Quote Reply
Re: How to add new links to front page? In reply to
tim,
In 3), <%$lastlink%> should be just <%lastlink%>. Use oldmoney's idea for showiung in reverse order.
Quote Reply
Re: How to add new links to front page? In reply to
Gotze;
If you got this run. How many links are going to display on the front page? Is it going to display all the new links just added in? Or just only the first ink or the last link?

What I really want is to display all of them in the frontpage.
Quote Reply
Re: How to add new links to front page? In reply to
It's working, yes! It is meant for showing a certain number of links, for example 5, or 8, or whatever. These are the most recently added links, regardsless of when they were added (so, for example, three from today and two from yesterday). You set that X nubmer in the script (see my instruction on my site, link above).
What I like about this is that you can design your homepage more precisely, so the links fit in with other things there. You get a more consitent 'feel' than you get with the What's New page.
If showing all new links is what you want, try the SSI-solution described by Floristan.
> >