Gossamer Forum
Home : Products : Links 2.0 : Customization :

How to display the Last X Pick Links on homepage ?

Quote Reply
How to display the Last X Pick Links on homepage ?
Just like lastlink mod , but only select the pick links .
( Editor's Pick has been installed )

Thanks

Good luck ,

Micheal Chan
Quote Reply
Re: How to display the Last X Pick Links on homepage ? In reply to
Add conditional statements that checks the isPick Field for Yes value...shouldn't be too hard to hack.

Regards,

Eliot Lee
Quote Reply
Re: How to display the Last X Pick Links on homepage ? In reply to
base on lastlink , is it right ?

Thanks


--------------------------------------------------------
my $LASTX = 4;
$isPick = Yes; # added here
open (DB, "<$db_file_name") or &cgierr("unable to open database:$db_file_name.\nReason: $!");
my @lines = <DB>;
close DB;
for ($i=$#lines; $i>=$#lines - $LASTX; $i--) {
chomp $lines[$i];
@tmp = &split_decode ($lines[$i]);
%tmp = &array_to_hash (0, @tmp);
$lastpick .= &site_html_lastpick (%tmp); # changed here

}

Good luck ,

Micheal Chan
Quote Reply
Re: How to display the Last X Pick Links on homepage ? In reply to
I try many times , but It's not working.

Please help me again , Eliot Lee

Thank you very much

Good luck ,

Micheal Chan
Quote Reply
Re: How to display the Last X Pick Links on homepage ? In reply to
try this code:
Code:
sub isPick {
my ($i, $ispick);
my $max = 5;
open (DB, "<$db_file_name") or cgierr($!);
while (<DB>) {
chomp;
my @data = split_decode($_);
($data[$db_isPick] eq 'Yes') or next;
my %rec = &array_to_hash(0, @data);
$ispick .= &site_html_ispick(%rec);
last if ($i++ >= $max);
}
close (DB);
return ($ispick);
}
In site_html_home, add this:
Code:
isPick => \&isPick,
before %globals.

This assumed that in links.def, you have set $db_isPick to the index position of this field.

--Drew
Free, hot camel soup for Links hackers...
http://www.camelsoup.com
Quote Reply
Re: How to display the Last X Pick Links on homepage ? In reply to
Thanks , junko.

but I found a bug, It only select the first date pick links ever , not the last date pick links .

May be add another field called 'Award Date' to recognise
what is the last pick ... what is the first pick...

Award Date hacks:
http://www.gossamer-threads.com/perl/forum/showflat.pl?Cat=&Board=L2Cust&Number=27077&page=&view=&sb=&part=2&vc=1

How to display the last x 'Award Date' pick links at homepage ?

junko , Eliot & anyone ...any ideas ?

Thank you very much

Good luck ,

Micheal Chan
Quote Reply
Re: How to display the Last X Pick Links on homepage ? In reply to
I don't know how you can call that a bug since that's how the lastlink mod works. it doesn't check the date, just whether or not the link was 'new', and then stops after 'x' number of links.

Now, if you really want to sort by a date before building the page, then you should add a field called PickDate. You should use the Perl time() subroutine to insert a timestamp. set $db_pickdate to the index position of this field.
Then, you'd use this:
Code:
sub isPick {
my (@pick, $ispick);
my $max = 5;
open (DB, "<$db_file_name") or cgierr($!);
while (<DB>) {
chomp;
my @data = split_decode($_);
($data[$db_isPick] eq 'Yes') or next;
push @pick, [ @data ];
}
close (DB);
my $i;
foreach (sort { ${$b}[$db_pickdate] <=> ${$a}[$db_pickdate] } @pick) {
my %rec = &array_to_hash(0, @{$_});
$ispick .= &site_html_ispick(%rec);
last if ($i++ >= $max);
}
return ($ispick);
}
--Drew
Free, hot camel soup for Links hackers...
http://www.camelsoup.com
Quote Reply
Re: How to display the Last X Pick Links on homepage ? In reply to
It's work perfect now ...

Thanks, junko. and sorry to say a bug, because I am so poor .

And I have another problem, how to sort the pick links list by PickDate , the last one at the top of the list page.

A how to guide for building a list of Editor's Pick page ,
some codes here , I try to hack it by myself , but I failed.


====================================================
local ($total, $link_results, $title_linked);
my (%link_output, $category_clean);
if ($build_pick_path =~ m,^$build_root_path/(.*)$,) {
&build_dir ($1);
}
$total = 0;
CATEGORY: foreach $category (sort keys %pick_links) {
LINK: for ($i = 0; $i < ($#{$pick_links{$category}}+1) / ($#db_cols + 1); $i++) {
$total++;
%tmp = &array_to_hash ($i, @{$pick_links{$category}});
$link_output{$category} .= &site_html_link (%tmp) . "\n";
}
}

Full here:
http://www.gossamer-threads.com/perl/forum/showflat.pl?Cat=&Board=L2Cust&Number=27077&page=&view=&sb=&vc=1


Thanks again


Good luck ,

Micheal Chan
Quote Reply
Re: How to display the Last X Pick Links on homepage ? In reply to
I already provied codes to sort by date:
Code:
foreach (sort { ${$b}[$db_pickdate] <=> ${$a}[$db_pickdate] } @pick) {
All you need to do is to add the field to %db_cols, and to system defaults, etc.

--Drew
Free, hot camel soup for Links hackers...
http://www.camelsoup.com
Quote Reply
Re: How to display the Last X Pick Links on homepage ? In reply to
It only work for the isPick at homepage, but not for the "Editor's Pick" page.

Thanks

Good luck ,

Micheal Chan
Quote Reply
Re: How to display the Last X Pick Links on homepage ? In reply to
Try this...
Code:
sub build_pick_page {
my (@pick, $ispick, $total, $title_linked);
if ($build_pick_path =~ m,^$build_root_path/(.*)$,) { &build_dir ($1); }
open (DB, "<$db_file_name") or cgierr($!);
while (<DB>) {
chomp;
my @data = split_decode($_);
($data[$db_isPick] eq 'Yes') or next;
push @pick, [ @data ];
}
close (DB);
foreach (sort { ${$b}[$db_pickdate] <=> ${$a}[$db_pickdate] } @pick) {
my %rec = &array_to_hash(0, @{$_});
$ispick .= &site_html_link(%rec);
}
$title_linked = &build_linked_title ("Picks");
$total = $#pick + 1;
open (PICK, ">$build_pick_path/$build_index") or cgierr ($!);
print "\tEditor's Picks: $total\n";
print PICK &load_template ("pick.html", {
'results' => $ispick,
'title_linked' => $title_linked,
'total' => $total,
%globals
});
close PICK;
}
--Drew
Free, hot camel soup for Links hackers...
http://www.camelsoup.com
Quote Reply
Post deleted by monshow In reply to
Quote Reply
Re: How to display the Last X Pick Links on homepage ? In reply to
It's not working ...

Could you hacks base on this code ?


sub build_pick_page {
# --------------------------------------------------------
# Creates a "Editor's Pick" page.
local ($total, $link_results, $title_linked);
my (%link_output, $category_clean);
if ($build_pick_path =~ m,^$build_root_path/(.*)$,) {
&build_dir ($1);
}
$total = 0;
CATEGORY: foreach $category (sort keys %pick_links) {
LINK: for ($i = 0; $i < ($#{$pick_links{$category}}+1) / ($#db_cols + 1); $i++) {
$total++;
%tmp = &array_to_hash ($i, @{$pick_links{$category}});
$link_output{$category} .= &site_html_link (%tmp) . "\n";
}
}
foreach $category (sort keys %pick_links) {
$category_clean = &build_clean ($category);
$link_results .= qq|<P><A HREF="$build_root_url/$category/$build_index">$category_clean</A>\n|;
$link_results .= $link_output{$category};
}
$title_linked = &build_linked_title ("Picks");
open (PICK, ">$build_pick_path/$build_index") or cgierr ("unable to open editor's picks page: $build_pick_path/$build_index. Reason: $!");
print "\tEditor's Picks: $total\n";
print PICK &site_html_pick(@pick_links);
close PICK;
}


Thanks again & agian


Good luck ,

Micheal Chan
Quote Reply
Re: How to display the Last X Pick Links on homepage ? In reply to
Why did you re-post the Mod instructions? Definite waste of bandwidth and disk space.

Regards,

Eliot Lee
Quote Reply
Re: How to display the Last X Pick Links on homepage ? In reply to
I feel so sorry, because I hope junko to answer my question ...

no again .....

Good luck ,

Micheal Chan
Quote Reply
Re: How to display the Last X Pick Links on homepage ? In reply to
What isn't working? Do you have template called pick.html, with the tags 'results' and 'total' in them?

--Drew
Free, hot camel soup for Links hackers...
http://www.camelsoup.com
Quote Reply
Re: How to display the Last X Pick Links on homepage ? In reply to
I am sorry to reply too late . I make a mistake by upper case & lower case before, I change it and it is work ...

Thank you very very very very much ...........
Now it is perfect ....


Good luck ,

Micheal Chan