Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Show Last Links. This is correct?

Quote Reply
Show Last Links. This is correct?
Hi have found this thread:

http://gossamer-threads.com/perl/forum/showthreaded.pl?Cat=&Board=LSQLNG&Number=153582&page=&view=&sb=&vc=1#Post153582

And I have modified this global to show in the home page or others the 10 last links added to links directory:

Add this global in build options/Template globals:

Global name: Lastlinks10

sub {
my $tags = shift;
my $table = $DB->table('Links');
$table->select_options ('ORDER BY Add_Date DESC', 'LIMIT 10');
my $sth = $table->select;
my @output;
while (my $link = $sth->fetchrow_hashref) {
push (@output, $link);
}
return { Lastlinks10_loop => \@output };
}

Go to the templates (home.html or others) and add this:

<%Lastlinks10%>
<%loop Lastlinks10_loop%>
<a href="<%db_cgi_url%>/jump.cgi?ID=<%ID%>"><b><%Title%></a>


<%if Description%>
<%Description%>
<%endif%>

Date: <%Add_Date%>
<%endloop%>

from <a href="... to Date:<%Add_Date%> you can format the html at your convenience.

This is correct? Apparently works fine :)

Another doubt: How to display the words or expressions most searched? For example, I need to display to the public one spy page (new template) with the top 50 words searched in the directory & the top 50 last words searched. Or show to the public one spy popup with the last 5 searches & the 5 words or expressions most searched. Any ideas or mods or hacks or plugins?

Thank you very much.

Quote Reply
Re: Show Last Links. This is correct? In reply to
Hi,

Same idea, use a global:

Top10Searches =>
Code:
sub {
my $tags = shift;
my $table = $DB->table('SearchLog');
$table->select_options ('ORDER BY Results DESC', 'LIMIT 10');
my $sth = $table->select;
my @output;
while (my $link = $sth->fetchrow_hashref) {
push (@output, $link);
}
return { Top10Searches_loop => \@output };
}
And then use <%Top10Searches%> tag and the loop variable.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Show Last Links. This is correct? In reply to
Hi!
tricky question .. how to display only first 5 words of description and then end it with "..." like etc.

Gregor
Quote Reply
Re: [sc2utp] Show Last Links. This is correct? In reply to
Try changing

while (my $link = $sth->fetchrow_hashref) {
push (@output, $link);
}

to...

while (my $link = $sth->fetchrow_hashref) {
$link->{Description} =~ s/^(\w+\s\w+\s\w+\s\w+\s\w+).*$/$1.../;
push (@output, $link);
}

There has gotta be an easier way that doing \w+\s x 5 but I can't think straight at the moment - I may even have it wrong as it is but it's worth a try.

Last edited by:

PaulWilson: Sep 15, 2001, 2:45 PM
Quote Reply
Re: [PaulWilson] Show Last Links. This is correct? In reply to
thanx .. it works

bye

Gregor
Quote Reply
Re: [Alex] Show Last Links. This is correct? In reply to
I'm trying out Top10Searches, but I'm not sure what the variable should be in the loop. I can't use things like Title, because the search terms don't have these associated with them.

What would be put in the loop to have the Top10Searches results show up on the page?

Many thanks Smile

DT
Quote Reply
Re: [DogTags] Show Last Links. This is correct? In reply to
Hi,

I don't know it off hand, but you can always put <%GT::Template::dump%> inside the loop and it will print out the tags that are available.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [PaulWilson] Show Last Links. This is correct? In reply to
That code works great for words, how would you do that for characters instead of words?

$link->{Title} =~ s/^(\w+\s\w+\s\w+\s\w+\s\w+).*$/$1.../;



~ ERASER


Free JavaScripts @ Insight Eye
Quote Reply
Re: [Eraser] Show Last Links. This is correct? In reply to
If you want only 30 chars, try:

$link->{Title} = (length $link->{Title} > 30) ? substr($link->{Title},0,30) . ' ...' : $link->{Title};

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Show Last Links. This is correct? In reply to
A perfect solution! Thanks Alex.



~ ERASER


Free JavaScripts @ Insight Eye

Last edited by:

Eraser: Sep 18, 2001, 3:33 PM
Quote Reply
Re: [Alex] Show Last Links. This is correct? In reply to
I don't mean to question da big chief but isn't that a bit lengthy?

Quote:
$link->{Title} = (length $link->{Title} > 30) ? substr($link->{Title},0,30) . ' ...' : $link->{Title};

Wouldn't this do the same job.....

$link->{Title} = s/^(.{30}).*$/$1.../;

If it is under 30 chars the whole thing will be shown otherwise the condensed version will be shown?

Last edited by:

PaulWilson: Sep 18, 2001, 7:43 PM
Quote Reply
Re: [PaulWilson] Show Last Links. This is correct? In reply to
Hmm nevermind....my code would be fine if you wanted ... after everything :)
Quote Reply
Re: [PaulWilson] Show Last Links. This is correct? In reply to
Hmm, not sure if I like this name changing thing. =) Yes, that would work too, but substr are quite a bit faster then regex's. =)

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Show Last Links. This is correct? In reply to
Ha you noticed. I was actually just testing but I am now Paul.

It would be great if the dot could be removed but as someone registered Paul already I had to add the dot :(
Quote Reply
Re: [Alex] Show Last Links. This is correct? In reply to
Based on the above codes for a 10 search results display, I have:

Top_10_Search

sub {
# Displays last 10 search terms.
my $tags = shift;
my $table = $DB->table('SearchLog');
$table->select_options ('ORDER BY Results DESC', 'LIMIT 10');
my $sth = $table->select;
my @output;
while (my $link = $sth->fetchrow_hashref) {
push (@output, $link);
}
return { Top_10_Search_loop => \@output };
}


Then:

<%loop Top_10_Search_loop%>
<tr>
<a href="/cgi-bin/search.cgi?query=$escaped"><%Term%></a></td>
<td><%HitCount%></td>
</tr>
<%endloop%>

... but alas no result show.



~ ERASER


Free JavaScripts @ Insight Eye

Last edited by:

Eraser: Sep 23, 2001, 8:12 AM
Quote Reply
Re: [Eraser] Show Last Links. This is correct? In reply to
Hi,

Did you add <%Top_10_Search%> which actually runs the function? It must be before the loop tag.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Show Last Links. This is correct? In reply to
Oops, no I didn't - but now I have, thanks!



~ ERASER


Free JavaScripts @ Insight Eye
Quote Reply
Re: [Eraser] Show Last Links. This is correct? In reply to
In Reply To:
<a href="/cgi-bin/search.cgi?query=$escaped"><%Term%></a></td>

When I try this, the search link does not go to the search term. "$escaped" ends up as the actual search term:

Quote:
<a href="/cgi-bin/linkssql/search.cgi?query=$escaped">fred</a>

How do I get $escaped to convert into the search term?

Thanks!

------------------------------------------
Quote Reply
Re: [DogTags] Show Last Links. This is correct? In reply to
Try:

<a href="/cgi-bin/search.cgi?query=<%GT::CGI::escape ($Term)%>"><%Term%></a>

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Show Last Links. This is correct? In reply to
Hi,

I would like to display also the categories of the links in the listing,
and link to the category instead of jumping to the link.

<%GT::Template::dump%> does not show me a tag for that.

In my old last-5 script I had this part ....

$link_catlink->select_options("order by ID DESC limit $limit");
my $sth = $link_catlink->select ( {isValidated=>'Yes'}, ['Title','LinkOwner','URL','Links.ID']);
my $i=0;


while (@data = $sth->fetchrow_array) {

# get category ID
my $catLinks = $link_catlink->select ( {LinkID=>$data[3]}, ['CategoryID'] );
$catID = $catLinks->fetchrow;
# get category name
my $cat_name = $category->select ({ID=>$catID},['Full_Name']);
$catName = $cat_name->fetchrow;
# set url for each Category
$clean_name = $category->as_url($catName);
$url = $CFG->{build_root_url} . "/" . $clean_name . "/" . $CFG->{build_index};



Possible to use something like that in combination with the script from this thread?

Michael


--
Michael Skaide

http://www.cycle24.de

Last edited by:

Michael Skaide: Jan 3, 2002, 9:02 AM