Gossamer Forum
Quote Reply
New Reviews by Category
Is there a way to show new/latest reviews by category? So as I drill down through the categories the reviews are displayed just for that category and it's children.

Currently I'm using this global to show new reviews for the whole database:

sub {
# Displays the newest links on the home page.
my ($output, $sth, $review);
my $search_db = $DB->table('Reviews');
$search_db->select_options ('ORDER BY Review_Date DESC');
$sth = $search_db->query_sth ( { Review_Validated => 'Yes' });
my $i=1;
review: while ($review = $sth->fetchrow_hashref) {
my $desc = $review->{Review_Contents};
unless (length $desc <= 30) {my $short = substr ($desc, 0, 200); $short =~ s/\s\S+?$//; $short .= " ..."; $review->{Review_Contents} = $short;}
$output .= Links::SiteHTML::display ('review_new', $review);
last review if ($i>=3);
$i++;
}
return $output;
}
Quote Reply
Re: [pshadow] New Reviews by Category In reply to
o.k. I think I figured out this one. I merged the Top Rated plugin and the New Review to come up with this that seems to work. I'm not a coded (at all :)) so if anyone sees some mistakes please let me know.

sub {
my ($output, $sth, $review);
my $cat = shift;
my $all_ids = $DB->table('Category')->children($cat);
push @$all_ids, $cat;
my $search_db = $DB->table('Reviews','Links','CatLinks','Category');
$search_db->select_options ('ORDER BY Review_Date DESC');
my $sth = $search_db->select (['Reviews.*'], GT::SQL::Condition->new(
['CategoryID', 'IN', $all_ids],
['Review_Validated', '=', 'Yes'])
);
my $i=1;
review: while ($review = $sth->fetchrow_hashref) {
my $desc = $review->{Review_Contents};
unless (length $desc <= 30) {my $short = substr ($desc, 0, 200); $short =~ s/\s\S+?$//; $short .= " ..."; $review->{Review_Contents} = $short;}
$output .= Links::SiteHTML::display ('review_new', $review);
last review if ($i>=3);
$i++;
}
return $output;
}
Quote Reply
Re: [pshadow] New Reviews by Category In reply to
Hi,

Like this global but need to use loop_reviews, tryed to change it but my limited skills put me in the corner once again.

I hope someone can help me out.

Thanks
Quote Reply
Re: [rascal] New Reviews by Category In reply to
Figured it out!