Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Building a Cool/New-Like Featured/Priority Page

(Page 1 of 2)
> >
Quote Reply
Building a Cool/New-Like Featured/Priority Page
I currently have an IsFeatured Yes/No tag for my links. I have things working great where such IsFeatured = Yes links will show up at the top of their categories.

I was wondering, however, how I would go about building a new Featured Links page, exactly like the Cool and New pages (but, of course, building all isFetured links). I have a featured_links.html template all ready to go... so I guess I need to know where to go from here? I'm guessing the logic is all there for the cool/new.

Thanks!

AD
Quote Reply
Re: [Jobu] Building a Cool/New-Like Featured/Priority Page In reply to
I guess that all depends on how you want it to display. The easiest method I can think of is to use a new perl file (featured.cgi) and include it using SSI; or you could just directly use featured.cgi with something like:

Code:

#!/usr/bin/perl
#================================
use strict;
use lib 'path/to/admin';
use Links qw/$DB $IN/;
Links::init('/path/to/admin');
use Links::SiteHTML;
local $SIG{__DIE__} = \&Links::fatal;
main();

sub main {
#---------------------------------------------------
#

my ($sth,$tab,$output);
$tab = $DB->table('Links');
$tab->select_options('LIMIT 2');
$sth = $tab->select( { isValidated => 'Yes', isFeatured => 'Yes' } );
while (my $rec = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display('link', $rec);
}
print $IN->header();
print Links::SiteHTML::display('your template name', $output);
}


Hopefully this code will work (I just copied it from other stuff). Limit is how many featured you want to display. Fill in the paths and template names and you should be good to go.

Good Luck!

- Jonathan
Quote Reply
Re: [jdgamble] Building a Cool/New-Like Featured/Priority Page In reply to
Thanks... I tried this, and got an error:

Code:

A fatal error has occured:
Can't use string ("

Please enable debugging in setup for more details.



I enabled debugging and a few errors resulted that could probably give more information.

However, I'm thinking the easiest thing to do is simply build in a code into nph-build.cgi like cool and new. I want, for example, spanned pages, which my sense is the code you offered will not do. I will look through nph-build and see if I can do it using the same logic.

In the meantime, I'm all ears if anyone has done this themselves in the past!
Quote Reply
Re: [Jobu] Building a Cool/New-Like Featured/Priority Page In reply to
Yeah, sorry. The last line should be:

Code:

print Links::SiteHTML::display('template_no_extension', { output => $output});



The problem with editing nph-build is that it will be overwritten anytime you upgrade/update links. Unless you are creating a plugin with a hook, I suggest you stay away from editing links original code.

If you want to show span pages, you could do something like:
Code:
my $pageNum = $IN->param('page') ||= 1;# number of links per pagemy $linksPP = 10;my $end = $linksPP*$pageNum;my $start = $end - $linksPP;$tab->select_options('LIMIT $start OFFSET $end');


Oh yeah, and you call it by featured.cgi?page=page number

I think that should work ?!

Hope this helps,

- Jonathan

Last edited by:

jdgamble: Aug 27, 2006, 8:46 PM
Quote Reply
Re: [jdgamble] Building a Cool/New-Like Featured/Priority Page In reply to
You make some good sense. Here's the situation.

featured.cgi is as follows:

Code:
#!/usr/local/bin/perl
#================================
use strict;
use lib '/var/home/moen/wiredbiz.com/cgi-bin/links/admin';
use Links qw/$DB $IN/;
Links::init('/var/home/moen/wiredbiz.com/cgi-bin/links/admin');
use Links::SiteHTML;
local $SIG{__DIE__} = \&Links::fatal;
main();

sub main {
#---------------------------------------------------
#

my ($sth,$tab,$output);
$tab = $DB->table('Links');
$tab->select_options('LIMIT 2');
$sth = $tab->select( { isValidated => 'Yes', isFeatured => 'Yes' } );
while (my $rec = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display('link', $rec);
}
print $IN->header();
print Links::SiteHTML::display('featured', { output => $output});
}


My featured.html template includes:

Code:
<%loop link_results_loop~%>
<p class="category"><%Links::Utils::format_title($title_loop, separator => $category_separator, no_escape_separator => $no_escape_category_separator, include_home => 0, link_type => 1)%></p>
<%include link2.html%>
<%~endloop%>


When I visit http://www.wiredbiz.com/...n/links/featured.cgi, I get the output, but no links.

I definitely have several links set as IsFeatured.

Any ideas?
Quote Reply
Re: [Jobu] Building a Cool/New-Like Featured/Priority Page In reply to
Sorry for the delayed reply.

You don't have to loop the link results in the template. It already being looped in the perl file by the 'while' statement.

Quote:

Links::SiteHTML::display('link', $rec);


That line takes care of the LINK template... so in your case you probably want to change it to display('link2', $rec);

Your featured template should be:

<%output%> for the link results...

Hope this helps,

- Jonathan
Quote Reply
Re: [jdgamble] Building a Cool/New-Like Featured/Priority Page In reply to
Ahh, my apologies! So I did that, and we're on the right track.

Now my only problem is that the New, Popular, Featured, and Modified tags all show up even when the link may not be New, Popular or Modified. Check out: http://www.wiredbiz.com/...n/links/featured.cgi.

How do I fix this?

Thanks man!
Quote Reply
Re: [jdgamble] Building a Cool/New-Like Featured/Priority Page In reply to
Oh, and where would I put the following paging code within the script?

Code:

my $pageNum = $IN->param('page') ||= 1;
# number of links per page
my $linksPP = 10;
my $end = $linksPP*$pageNum;
my $start = $end - $linksPP;
$tab->select_options('LIMIT $start OFFSET $end');
Quote Reply
Re: [Jobu] Building a Cool/New-Like Featured/Priority Page In reply to
Make sure your link2.html template uses conditionals to check for isNew. It might have gotten deleted by accident.

Example:

<%if isNew%>print new image<%endif%>
<%if isPopular%> print pop image<%endif%>
<%if isChange%> <img scr=.... <%endif%>
<%if isFeatured%>etc..<%endif%>

- Jonathan
Quote Reply
Re: [jdgamble] Building a Cool/New-Like Featured/Priority Page In reply to
Yep, I have:

Code:

<%if isFeatured eq 'Yes'%><span class="expired-item"><span>featured</span></span><%endif%>
<%if isNew%><span class="new-item"><span>new</span></span><%endif%>
<%if isChanged%><span class="updated-item"><span>updated</span></span><%endif%>
<%if isPopular%><span class="popular-item"><span>popular</span></span><%endif%>
Quote Reply
Re: [jdgamble] Building a Cool/New-Like Featured/Priority Page In reply to
Ahh, I got it. Had to add the following to the top of link2.html:

Code:

<%Links::Utils::load_link_info()%>
Quote Reply
Re: [Jobu] Building a Cool/New-Like Featured/Priority Page In reply to
As long as your "isFeatured" column has the same properties (enum, yes, no etc) as isNew, isPopular, and isChanged... you can call it the same way <%if isFeatured%>.... you don't need the eq 'yes' part.

Okay. Your main function should now look something like this:

Quote:

sub main {
#---------------------------------------------------
#
my $pageNum = $IN->param('page') ||= 1;
# number of links per page
my $linksPP = 10;
my $end = $linksPP*$pageNum;
my $start = $end - $linksPP;
my ($sth,$tab,$output);
$tab = $DB->table('Links');
$tab->select_options('LIMIT $start OFFSET $end');
$sth = $tab->select( { isValidated => 'Yes', isFeatured => 'Yes' } );
while (my $rec = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display('link2', $rec);
}
print $IN->header();
print Links::SiteHTML::display('featured', { output => $output});
}


I may have mistyped something on the pages part, but it should work.

(**crossing fingers...**)

- Jonathan
Quote Reply
Re: [jdgamble] Building a Cool/New-Like Featured/Priority Page In reply to
I got the following error:

Code:


A fatal error has occured:
Can't modify non-lvalue subroutine call at featured.cgi line 15.

Please enable debugging in setup for more details.


Line 15 is:

Code:

my $pageNum = $IN->param('page') ||= 1;
Quote Reply
Re: [Jobu] Building a Cool/New-Like Featured/Priority Page In reply to
Opps... I found a few mistakes... (I copied from something else).

Hopefully, this will work:

Code:

my $pageNum = $IN->param('page') || 1;
# number of links per page
my $linksPP = 10;
my $start = $linksPP*$pageNum - $linksPP;
my ($sth,$tab,$output);
$tab = $DB->table('Links');
$tab->select_options('LIMIT ' . $linksPP . ' OFFSET ' . $start);



Replace that with the lines that are like it.

You could probably also edit $linksPP to say

my $linksPP = $CFG->{build_links_per_page};

- Jonathan

Last edited by:

jdgamble: Aug 28, 2006, 7:39 PM
Quote Reply
Re: [jdgamble] Building a Cool/New-Like Featured/Priority Page In reply to
OK, I think I have it working now. It's listing 10 links per page, and I can call the subsequent pages by featured.cgi?page=x.

However, how do I get the spanned links to show up (i.e., << 1 of x >>).

I have the following in featured.html, but it does not seem to do anything:
Code:

<%if paging.num_hits%><div class="paging"><%Links::Utils::paging()%></div><%endif%>
Quote Reply
Re: [jdgamble] Building a Cool/New-Like Featured/Priority Page In reply to
Oh, and one other question... right now I have:

Code:

$sth = $tab->select( { isValidated => 'Yes', isFeatured => 'Yes' } );


This selects all validated and featured links. However, how would I select all Featured links OR all those links with an ExpiryDate less than a certain date?

Thanks man!
Quote Reply
Re: [Jobu] Building a Cool/New-Like Featured/Priority Page In reply to
You are going to have to set the paging options. You should be able to do something like this:

$rec->{url} = $CFG->{db_cgi_url} . "/featured.cgi";
$rec->{num_hits} = $sth->hits;
$rec->{current_page} = $IN->param('nh');

before you print the template. You will have to change $IN->param('page') to $IN->param('nh')

Quote:

This selects all validated and featured links. However, how would I select all Featured links OR all those links with an ExpiryDate less than a certain date?


Dates are not easily messed with. Besides keys and speed, that is why there is a isNew column instead of if date is new etc... In order to select all featured links OR something else you need an actual conditional statement.

eg. - if no featured links, then select something else

As far as selected expirydate less than a certain date, I suppose you could do:

$sth = $tab->select( { ExpiryDate => "< whatever format the date is"} );

I don't know if that would work since ExpiryDate is not a date field anyway (it wills say no payment required).

You just have to mess with it to get whatever outcome you are looking for.

Hope this helps,

- Jonathan
Quote Reply
Re: [jdgamble] Building a Cool/New-Like Featured/Priority Page In reply to
I seem to get an Internal Server Error wherever I put that additional code. Right now I have:

Code:

#!/usr/local/bin/perl
#================================
use strict;
use lib '/var/home/moen/wiredbiz.com/cgi-bin/links/admin';
use Links qw/$DB $IN/;
Links::init('/var/home/moen/wiredbiz.com/cgi-bin/links/admin');
use Links::SiteHTML;
local $SIG{__DIE__} = \&Links::fatal;
main();

sub main {
#---------------------------------------------------
#
my $pageNum = $IN->param('nh') || 1;
# number of links per page
my $linksPP = 10;
my $start = $linksPP*$pageNum - $linksPP;
my ($sth,$tab,$output);
$tab = $DB->table('Links');
$tab->select_options('ORDER BY Title', 'LIMIT ' . $linksPP . ' OFFSET ' . $start);
$sth = $tab->select( { isValidated => 'Yes', isNew => 'Yes' } );
while (my $rec = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display('link2', $rec);
}
$rec->{url} = $CFG->{db_cgi_url} . "/featured.cgi";
$rec->{num_hits} = $sth->hits;
$rec->{current_page} = $IN->param('nh');
print $IN->header();
print Links::SiteHTML::display('featured', { output => $output});
}



I also tried the additional code in other places.

Any suggestions?

Last edited by:

Jobu: Aug 28, 2006, 9:44 PM
Quote Reply
Re: [Jobu] Building a Cool/New-Like Featured/Priority Page In reply to
To be more specific, do something like this:

Code:

my $tags;
$tags->{'paging.url'} = $CFG->{db_cgi_url} . "/featured.cgi";
$tags->{'paging.num_hits'} = $tab->hits;
$tags->{'paging.current_page'} = $IN->param('nh');
$tags->{'output'} = $output;
print $IN->header();
print Links::SiteHTML::display('featured', $tags);


You will also have to change the top line to this: use Links qw/$DB $IN $CFG/;

- Jonathan
Quote Reply
Re: [jdgamble] Building a Cool/New-Like Featured/Priority Page In reply to
OK, now I'm getting the display again but no paging.

My CGI file is:

Code:
#!/usr/local/bin/perl
#================================
use strict;
use lib '/var/home/moen/wiredbiz.com/cgi-bin/links/admin';
use Links qw/$DB $IN $CFG/;
Links::init('/var/home/moen/wiredbiz.com/cgi-bin/links/admin');
use Links::SiteHTML;
local $SIG{__DIE__} = \&Links::fatal;
main();

sub main {
#---------------------------------------------------
#
my $pageNum = $IN->param('nh') || 1;
# number of links per page
my $linksPP = 10;
my $start = $linksPP*$pageNum - $linksPP;
my ($sth,$tab,$output);
$tab = $DB->table('Links');
$tab->select_options('ORDER BY Title', 'LIMIT ' . $linksPP . ' OFFSET ' . $start);
$sth = $tab->select( { isValidated => 'Yes', isNew => 'Yes' } );
while (my $rec = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display('link2', $rec);
}
my $tags;
$tags->{'paging.url'} = $CFG->{db_cgi_url} . "/featured.cgi";
$tags->{'paging.num_hits'} = $tab->hits;
$tags->{'paging.current_page'} = $IN->param('nh');
$tags->{'output'} = $output;
print $IN->header();
print Links::SiteHTML::display('featured', $tags);
}


And my template has:

Code:
<%if paging.num_hits%><div class="paging"><%Links::Utils::paging()%></div><%endif%><%output%><%if paging.num_hits%><div class="paging"><%Links::Utils::paging()%></div><%endif%>
Quote Reply
Re: [Jobu] Building a Cool/New-Like Featured/Priority Page In reply to
Hmmm... try testing to make sure each variable is printing correctly in the template:

<%paging.num_hits%>
<%paging.current_page%>
<%paging.url%>

The paging function should automatically pull these variables, otherwise I did something wrong in the code.

- Jonathan
Quote Reply
Re: [jdgamble] Building a Cool/New-Like Featured/Priority Page In reply to
In Reply To:
Hmmm... try testing to make sure each variable is printing correctly in the template:

<%paging.num_hits%>
<%paging.current_page%>
<%paging.url%>

The paging function should automatically pull these variables, otherwise I did something wrong in the code.


<%paging.num_hits%> gives me 1
<%paging.current_page%> is null
<%paging.url%>
gives me http://www.WiredBIZ.com/cgi-bin/links/featured.cgi
Quote Reply
Re: [Jobu] Building a Cool/New-Like Featured/Priority Page In reply to
Okay, current page isn't working because there is not input. I guess the fetchrow_hashref is messing with the hits count.

Try changed the lines to this:

Code:

$sth = $tab->select( { isValidated => 'Yes', isNew => 'Yes' } );
my $hits = $tab->hits;
while (my $rec = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display('link2', $rec);
}
my $tags;
$tags->{'paging.url'} = $CFG->{db_cgi_url} . "/featured.cgi";
$tags->{'paging.num_hits'} = $hits;
$tags->{'paging.current_page'} = $pageNum;

- Jonathan
Quote Reply
Re: [jdgamble] Building a Cool/New-Like Featured/Priority Page In reply to
OK, so now I have the following and I get an internal server error:

Code:

#!/usr/local/bin/perl
#================================
use strict;
use lib '/var/home/moen/wiredbiz.com/cgi-bin/links/admin';
use Links qw/$DB $IN $CFG/;
Links::init('/var/home/moen/wiredbiz.com/cgi-bin/links/admin');
use Links::SiteHTML;
local $SIG{__DIE__} = \&Links::fatal;
main();

sub main {
#---------------------------------------------------
#
my $pageNum = $IN->param('nh') || 1;
# number of links per page
my $linksPP = 10;
my $start = $linksPP*$pageNum - $linksPP;
my ($sth,$tab,$output);
$tab = $DB->table('Links');
$tab->select_options('ORDER BY Title', 'LIMIT ' . $linksPP . ' OFFSET ' . $start);
$sth = $tab->select( { isValidated => 'Yes', isFeatured => 'Yes' } );
my $hits = $tab->hits;
while (my $rec = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display('link2', $rec);
}
my $tags;
$tags->{'paging.url'} = $CFG->{db_cgi_url} . "/featured.cgi";
$tags->{'paging.num_hits'} = $hits;
$tags->{'paging.current_page'} = $pageNum;
print $IN->header();
print Links::SiteHTML::display('featured', $tags);
}
Quote Reply
Re: [Jobu] Building a Cool/New-Like Featured/Priority Page In reply to
I don't have any clue why you would get an internal server error, but I did notice that you are not sending the output tag. Try exporting the tags like this:

Code:

$tags->{'paging'}->{'url'} = $CFG->{db_cgi_url} . "/featured.cgi";
$tags->{'paging'}->{'num_hits'} = $hits;
$tags->{'paging'}->{'current_page'} = $pageNum;
$tags->{'output'} = $output;


Sorry for the long painful process, but we will get it. Wink

- Jonathan
> >