Gossamer Forum
Quote Reply
Modify a Category sub
Hello,

I used the following sub to show on Detail pages 10 links what have the same Category:

[/i]sub {
my $tags = shift;
my $id = $tags->{ID};
my $catid = $DB->table('CatLinks')->select({LinkID=>$id})->fetchrow_hashref->{CategoryID};
my $db = $DB->table('CatLinks','Links');
my $cond = GT::SQL::Condition->new( 'CatLinks.CategoryID','=',$catid, 'CatLinks.LinkID','<>',$id);
$db->select_options("ORDER BY Hits DESC", "LIMIT 10");
my $rs = $db->select($cond,['Links.*'])->fetchall_hashref or return;
my $output ="";
foreach(@$rs){
$output .= Links::SiteHTML::display('link_detail',$_);
}
return $output;
}[/i]

Now, I would like change this sub to show on a new Page 10 links of a certain category, as an example ID 60.
I will used this on a Page create with the PageBuilder Plugin.


I hope anyone understand my english Unsure

Greetings from Germany,
QIX
Quote Reply
Re: [qix] Modify a Category sub In reply to
Moin moin,

if you have a variable <%CertainCategoryID%> in your template your sub should look like

Code:
sub {
my $tags = shift;
my $catid = $tags->{CertainCategoryID};
my $id = $tags->{ID};
my $db = $DB->table('CatLinks','Links');
my $cond = GT::SQL::Condition->new( 'CatLinks.CategoryID','=',$catid, 'CatLinks.LinkID','<>',$id);
$db->select_options("ORDER BY Hits DESC", "LIMIT 10");
my $rs = $db->select($cond,['Links.*'])->fetchall_hashref or return;
my $output ="";
foreach(@$rs){
$output .= Links::SiteHTML::display('link_detail',$_);
}
return $output;
}

Regards

Merten
Quote Reply
Re: [neves] Modify a Category sub In reply to
neves wrote:
Moin moin,

if you have a variable <%CertainCategoryID%> in your template your sub should look like

Code:
sub {
my $tags = shift;
my $catid = $tags->{CertainCategoryID};
my $id = $tags->{ID};
my $db = $DB->table('CatLinks','Links');
my $cond = GT::SQL::Condition->new( 'CatLinks.CategoryID','=',$catid, 'CatLinks.LinkID','<>',$id);
$db->select_options("ORDER BY Hits DESC", "LIMIT 10");
my $rs = $db->select($cond,['Links.*'])->fetchall_hashref or return;
my $output ="";
foreach(@$rs){
$output .= Links::SiteHTML::display('link_detail',$_);
}
return $output;
}


Regards

Merten

Hi Merten,

thanks for your Help.
I dont have a variable <%CertainCategoryID%> because there is no linking to Category.
Is it possible to say:

sub {
my $tags = shift;
my $catid = $tags->{60};
....
....

To show only links from the Category with the ID 60 ??

Regards,
Frank
Quote Reply
Re: [qix] Modify a Category sub In reply to
You can define the variable in your template:

<%set CertainCategoryID = 60%>

Regards

Merten
Quote Reply
Re: [neves] Modify a Category sub In reply to
Hi Merten,

that's it.

Thanx for your Support.

Regards,
Frank
Quote Reply
Re: [qix] Modify a Category sub In reply to
Hello,

How can I automate this to show 10 links on every category page using the tag <%category_id%>?

I tried:

<%set CertainCategoryID = <%category_id%> %>

Thanks
Quote Reply
Re: [socrates] Modify a Category sub In reply to
Anyone knows how I can set this up in the links template? thanks.

socrates wrote:
Hello,

How can I automate this to show 10 links on every category page using the tag <%category_id%>?

I tried:

<%set CertainCategoryID = <%category_id%> %>

Thanks
Quote Reply
Re: [socrates] Modify a Category sub In reply to
Hi,

the correct syntax is:

<%set CertainCategoryID = $category_id%>

Regards

Merten
Quote Reply
Re: [neves] Modify a Category sub In reply to
Thanks - I had tried that and did not seem to work or may be I made a typo. Will try again.