Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Adding links to homepage

(Page 1 of 2)
> >
Quote Reply
Adding links to homepage
Hi,

I'm trying to update my Links2 directory to SQL but I have a lot of mods and I'm getting stuck. Please can anyone give me some hints on how to add featured sites (like an editor's pick) to the homepage? I have a flag for whether the links are featured or not - I just can't see how to get them on there.

Thanks,
Laura.

Quote Reply
Re: Adding links to homepage In reply to
Create a global with the following code:

my $search_db = $DB->table('Links');
$search_db->select_options ('ORDER BY Add_Date DESC', 'LIMIT 1');
my $sth = $search_db->select;
while (my $hit = $sth->fetchrow_hashref) {
$output .= qq!
$hit->{Title}<BR>$hit->{URL}
$hit->{Description}!; }
return $output;
~;

You can try that out but Im not sure if it is correct as I can't remember the table names of the top of my head.

Paul Wilson.
new - http://www.wiredon.net
Quote Reply
Re: Adding links to homepage In reply to
Paul,

Thanks a lot. The global I ended up with is:

sub {
# Displays the featured links on the home page.
my ($output,$sth,$link);
my $search_db = $DB->table('Links');
$search_db->select_options ('ORDER BY Add_Date DESC');
$sth = $search_db->select ( { isFeatured => 'Yes'});
while ($link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('link', $link);
}
return $output;
}

Laura.

Quote Reply
Re: Adding links to homepage In reply to
Hope the code I provided was of some use.

Paul Wilson.
new - http://www.wiredon.net
Quote Reply
Re: Adding links to homepage In reply to
Extremely useful - I had no idea where to start from.
Thanks again.

Laura.

Quote Reply
Re: Adding links to homepage In reply to
Well it looks like you know what you are doing to me by the way you modified the code.Smile

Paul Wilson.
new - http://www.wiredon.net
Quote Reply
Re: Adding links to homepage In reply to
Thanks for the vote of confidence! I think that my perl isn't too bad but I'm only a few days into playing around with linksSQL so I haven't found where everything is yet. I didn't realise that it was so easy to change things using the globals and templates - I have been using site_html.pl in links2 but I wish I'd started using the templates straight away - it would have made the move much easier.

Laura.

Quote Reply
Re: Adding links to homepage In reply to
Yes I had the same trouble. I started off using site_html.pl but then realised that using templates was a better option...even more so because most of the mods available are for template users although they can be modified to be used with site_html.pl

When you first install Links SQL it is very daunting compared to Links2 as there are many more files and it operates dfferently etc.......but once you get familiar with the script there is so much that can be done with it.

Paul Wilson.
new - http://www.wiredon.net
Quote Reply
Re: Adding links to homepage In reply to
This forum is great!

That was exactly what I have been trying to do too. Thanks so much for sharing your knowledge with everyone, especially helpful to people like me who don't know perl at all.

I'm limiting my Featured list links to 3 links on the home page. What I would really like to do is have the routine pick 3 links at random to display.

That way, each time the home page is rebuilt, it will have three different people on it. Does anyone know how I would go about getting it to do that?

Thanks,

Bryan

Quote Reply
Re: Adding links to homepage In reply to
Hi,

Something like:

Code:
my $link_db = $DB->table('Links');
my $total = $link_db->count ( { isValidated => 'Yes' });
my $output;
for (1 .. 3) {
my $rand = int (rand() * $total);
$link_db->select_options ("LIMIT $rand, 1");
my $sth = $link_db->select ({ isValidated => 'Yes' });
my $link = $sth->fetchrow_hashref;
$output .= Links::SiteHTML::display ('link', $link);
}
return $output;
should do the trick. What this does is find out the total number of validated links, then picks a random number from that total, and then selects the link. It does this 3 times and then returns the output.

This is untested, but should work.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Post deleted by TheFox In reply to
Quote Reply
Re: Adding links to homepage In reply to
Just modify the line
$sth = $search_db->select ( {});
and in the brackets put your selection criteria such as Category => 'Name_of_Category'.

Quote Reply
Re: Adding links to homepage In reply to
In Reply To:
Just modify the line
$sth = $search_db->select ( {});
and in the brackets put your selection criteria such as Category => 'Name_of_Category'.
The Code didn't work, There is no Category field in Links table.

Regards

TheFox


Quote Reply
Re: Adding links to homepage In reply to
Hi Alex,

Please Help!

regards

TheFox

Quote Reply
Re: Adding links to homepage In reply to
Hi Alex,

Is there any way to specify the categories? I need to add links from a specify category into homepage ! Please Help.

Thanks

TheFox


Quote Reply
Re: Adding links to homepage In reply to
Hi Alex,

Are you there???? Please Help!

regards

TheFox

Quote Reply
Re: Adding links to homepage In reply to
You were told how to do this by afinlr.......

my $link_db = $DB->table('Links');
my $total = $link_db->count ( { isValidated => 'Yes' });
my $output;
for (1 .. 3) {
my $rand = int (rand() * $total);
$link_db->select_options ("LIMIT $rand, 1");
my $sth = $link_db->select ({ isValidated => 'Yes', Category => 'Your_category' });
my $link = $sth->fetchrow_hashref;
$output .= Links::SiteHTML::display ('link', $link);}
return $output;


Paul
Installations:http://wiredon.net/gt/
Support: http://wiredon.net/forum/

Quote Reply
Re: Adding links to homepage In reply to
Hi Paul,

It is not work!!

TheFox

Quote Reply
Re: Adding links to homepage In reply to
A little more info please...........are there errors?....what type?...where did you add the code?

Paul
Installations:http://wiredon.net/gt/
Support: http://wiredon.net/forum/

Quote Reply
Re: Adding links to homepage In reply to
Oh my bad.

You would need something like.....

my $cat_db = $DB->table('Category');
my $sth = $cat_db->select ({ Name => 'Your_category' });


Paul
Installations:http://wiredon.net/gt/
Support: http://wiredon.net/forum/

Quote Reply
Re: Adding links to homepage In reply to
Hi Paul,

The Full code please.

TheFox

Quote Reply
Re: Adding links to homepage In reply to
You should try to do it yourself so you learn for next time.

You can't always take the easy route...but if you do, something is needed in return by the person giving ($)

Paul
Installations:http://wiredon.net/gt/
Support: http://wiredon.net/forum/

Quote Reply
Re: Adding links to homepage In reply to
I have try the code as follow

sub {
my ($showlinks,$sth,$link);
my $search_db = $DB->table('CatLinks','Links');
$search_db->select_options ('ORDER BY Links.Add_Date DESC','LIMIT 30');
$sth = $search_db->select ( { Links.isValidated => 'Yes' , Links.ID => CatLinks.LinkID ,CatLinks.CategoryID = '1'});
while ($link = $sth->fetchrow_hashref) {
$showlinks .= Links::SiteHTML::display ('link', $link);
}
return $showlinks;
}

But it's not work

Please Help

TheFox

Quote Reply
Re: Adding links to homepage In reply to
The Error Message say:

Bareword "Links" not allowed while "strict subs" in use at (eval 13) line 6.
Bareword "Links" not allowed while "strict subs" in use at (eval 13) line 6.
Bareword "CatLinks" not allowed while "strict subs" in use at (eval 13) line 6.
Bareword "LinkID" not allowed while "strict subs" in use at (eval 13) line 6.
Bareword "CatLinks" not allowed while "strict subs" in use at (eval 13) line 6.
Bareword "CategoryID" not allowed while "strict subs" in use at (eval 13) line 6.

TheFox

Quote Reply
Re: Adding links to homepage In reply to
You aren't following my example.....

Where did I mention this?

In Reply To:
$sth = $search_db->select ( { Links.isValidated => 'Yes' , Links.ID => CatLinks.LinkID ,CatLinks.CategoryID = '1'});

Paul
Installations:http://wiredon.net/gt/
Support: http://wiredon.net/forum/

> >