Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Link of the day..

(Page 2 of 2)
> >
Quote Reply
Re: [Alex] Link of the day.. In reply to
Where would the <%set Random_Category = 3%> be placed?

Would it be:

Code:
<%Random_Link%>
<%set Random_Category = 3%>
<%loop Random_Loop%>
Random: <%Title%>: <%URL%><BR>
<%endloop%>

Many thanks! Cool



------------------------------------------
Quote Reply
Re: [DogTags] Link of the day.. In reply to
No, it has to come before the call to <%Random_Link%>.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Link of the day.. In reply to
Hey Mr. Alex Wink

Still tweeking htis random thread thingy. I'm able to get it going, but it doesn't work dynamically on the static pages. What I'm hoping for is to have it work like the ssi option did (each page reload gives you a different set of links)

The html code I used is perfect, except for the dynamic issue on static pages. Is there a way around this?

code I used:
Code:
<%Random_Link%>
<%loop Random_Loop%>
<p><b><A href="<%db_cgi_url%>/detail_page.cgi?ID=<%ID%>"><%Title%></b><br><%Description%></A>
[<A href="<%db_cgi_url%>/detail_page.cgi?ID=<%ID%>">more</A>]
<br>
<%endloop%>

Quote Reply
Re: [Evoir] Link of the day.. In reply to
Hi,

Do the same thing as before, save the html you pasted to some template (lets call it random.html) and then add ssi that looks like:

<!--#include virtual="/cgi-bin/links/page.cgi?p=random"-->

and the SSI will parse and load the random.html template.

Hope that helps,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Link of the day.. In reply to
Smile hehe hehe

it works CoolBlushTongue

Alex. I like your mind.

I now understand so much more about LinksSQL. It's all in the global variables. The reason I have so much trouble, is that I don't know perl. You don't really have to ever "hack" LinksSQL, because you can do everything from within the program (if you know some perl). Very cool beans. (Although, I'm still gonna have to ask questions like these. Hopefully, it helps alot more people than just me.

This is soo friggin cool. Thanks.

Last edited by:

Evoir: Nov 23, 2001, 5:26 PM
Quote Reply
Re: [Alex] Link of the day.. In reply to
I've been still trying to implement this. here's what I've got.

I created a gobal called Random_Link:

Code:
sub {
my $tags = shift;
my $link_db = $DB->table('Links','CatLinks');
my $cat_id = $tags->{Random_CatID};
my $limit = $tags->{Random_Limit} || 3;
my (@output, $sth);
$link_db->select_options ('ORDER BY RAND()', "LIMIT $limit");
if ($cat_id) {
$sth = $link_db->select ( { CategoryID => $cat_id });
}
else {
$sth = $link_db->select;
}
while (my $hash = $sth->fetchrow_hashref) {
push @output, $hash;
}
return { Random_Loop => \@output }
}

Then I created a template called random.html:

Code:
<%set Random_Category = 9%>
<%Random_Link%>
<%loop Random_Loop%>
<p> <b><%body_font%><a href="<%URL%>"><%Title%></a></b> <%Description%>
[<a href="<%URL%>">more</A>]</%body_font%></p>
<%endloop%>

Then, I called this template from a seperate category page, that has been defined in the browser to be called for a certain category, let's say category 9.

Code:
<!--#include virtual="/cgi-bin/Links/page.cgi?p=random"-->

It does not seem to differentiate and only send me items from category 9, instead, it sends me randoms from all the categories.

Perhaps there is still something missing. Unsure
Can you take a look Alex?

Last edited by:

Evoir: Dec 11, 2001, 11:47 PM
Quote Reply
Re: [Evoir] Link of the day.. In reply to
I tried Evoir's stuff, but I got an error message.

Everything was the same, except:

1. I called my template file randomssi.html instead of random.html (which I already had)

2. I dropped the random category piece of the loop for now and used:

Quote:
<%Random_Link%>
<%loop Random_Loop%>
<p> <b><%body_font%><a href="<%URL%>"><%Title%></a></b> <%Description%>
[<a href="<%URL%>">more</A>]</%body_font%></p>
<%endloop%>

Here is the error message that I got:

Quote:
A fatal error has occured:

Can't call method "fetchrow_hashref" on an undefined value at (eval 4) line 14.

Would anyone know where I am messing up?

Thanks.

------------------------------------------
Quote Reply
Re: [Alex] Link of the day.. In reply to
alex,

can you help me figure out why it is not discriminating which category it pulls from? Smile

Quote Reply
Re: [Alex] Link of the day.. In reply to
pretty please? Blush

Quote Reply
Re: [Alex] Link of the day.. In reply to
In Reply To:

Code:
Random_Link => sub {
my $tags = shift;
my $link_db = $DB->table('Links','CatLinks');
my $cat_id = $tags->{Random_CatID};
my $limit = $tags->{Random_Limit} || 3;
my (@output, $sth);
$link_db->select_options ('ORDER BY RAND()', "LIMIT $limit");
if ($cat_id) {
$sth = $link_db->select ( { CategoryID => $cat_id });
}
else {
$sth = $link_db->select;
}
while (my $hash = $sth->fetchrow_hashref) {
push @output, $hash;
}
return { Random_Loop => \@output }
}

It works great, I just would like to add another condition...I would like the random links to be validated links Txs FMP
Quote Reply
Re: [Alex] Link of the day.. In reply to
Just wanted to add what's already pointed out here.

This global is pulling date from ALL categories regardless of the <%set Random_Category = 3%> setting.

Do we have a fix for this.

I sincerely hope so Unsure

--------------------------------
Privacy Software
Quote Reply
Re: [Alex] Link of the day.. In reply to
OK, something's obviously up with this very good global that’s preventing it from working as advertised.

The problem is it's supposed to list only from the category number, but actually lists from all categories. Perhaps it's something to do with <%set Random_Category = 3%> not being matched in the global? Sorry I don't have the perl know-how to figure this out!

Here it is unmodified:


<%set Random_Category = 3%>
<%Random_Link%>
<%loop Random_Loop%>
<%Title%>
<%endloop%>


Random_Link

sub {
my $tags = shift;
my $link_db = $DB->table('Links','CatLinks');
my $cat_id = $tags->{Random_CatID};
my $limit = $tags->{Random_Limit} || 3;
my (@output, $sth);
$link_db->select_options ('ORDER BY RAND()', "LIMIT $limit");
if ($cat_id) {
$sth = $link_db->select ( { CategoryID => $cat_id });
}
else {
$sth = $link_db->select;
}
while (my $hash = $sth->fetchrow_hashref) {
push @output, $hash;
}
return { Random_Loop => \@output }

}

--------------------------------
Privacy Software
Quote Reply
Re: [BLOOD] Link of the day.. In reply to
OK, I found another thread with similar code that works good.

But can this global be changed to allow a category and all subcategories below it to be listed from.

As it is you pass in individual categories like:

page.cgi?p=include&Random_CatID=6&Random_CatID=7

sub {
my $tags = shift;
my $limit = ($tags->{Random_Limit} =~ /^(\d+)$/) ? $1 : 3;
my @parents = $IN->param('Random_CatID');
my @cat_ids;
foreach my $id (@parents) {
push @cat_ids, $id, $DB->table('Category')->children($id);
}
my $link_db = $DB->table('Links','CatLinks');
$link_db->select_options ('ORDER BY RAND()', "LIMIT $limit");
my $condition = GT::SQL::Condition->new( 'Description', 'IS NOT', \'NULL','isValidated','=','Yes');
if (@cat_ids) {
$condition->add('CategoryID', 'IN', \@cat_ids);
}
my $sth = $link_db->select($condition);
my @output;
while (my $hash = $sth->fetchrow_hashref) {
push @output, $hash;
}
return { Random_Loop => \@output }
}

--------------------------------
Privacy Software
Quote Reply
Re: [BLOOD] Link of the day.. In reply to
On a first glance I would say that you need to either use Random_Category OR Random_CatID.

Try changing it to <%set Random_CatID = 3%>
Quote Reply
Re: [BLOOD] Link of the day.. In reply to
As far as I can see this should list from a category and all subcategories as it is. I think that the extra category in the example is just another category - not a subcategory - and it should then use all the subcategories of both category 6 and category 7.
> >