Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Last 10 reviews posted

Quote Reply
Last 10 reviews posted
Hi,

I'm using a global (originally posted by Andy) that I've slightly modified to display the last 10 reviews posted. I must warn you my Perl coding skills are fairly rudimentary to say the least so I'm not sure how good the coding is...

At the moment this works to a certain extent in that it displays the Review author, subject and date but not the link title the review refers to.

Code:
sub {
my ($output,$hit);
my $table = $DB->table('Reviews');
$table->select_options('ORDER BY Review_Date','DESC','LIMIT 10');
# Only select validated reviews
my $sth = $table->select({Review_Validated => 'Yes'}) || return $GT::SQL::error;
while (my $hit = $sth->fetchrow_hashref()) {
# Modify short date format to mini format
$hit->{Review_Date}=GT::Date::date_transform($hit->{Review_Date},"%yyyy%-%mm%-%dd%","%dd% %mmm% %yy%");
$output .= Links::SiteHTML::display('newreviewsdate', $hit);
}
return $output;
}

So I'd like to find a way to integrate into this global a query to get the <%Title%> of the link the reviews refer to.

I tried adding this :
Code:
my $sth = $table->select({Review_Validated => 'Yes'},{ Review_LinkID => $ID }) || return $GT::SQL::error;
since the Review_LinkID is the same as the link $ID but can't figure out whether there needs to be another database query to the Links table in order to get the Title or not.

Does anybody have an idea on where I should be looking ?

Thanks, John
Significant Media
Quote Reply
Re: [Jag] Last 10 reviews posted In reply to
Try changing the table from ('Reviews') to ('Reviews','Links') - that should give you access to the title (but it may also cause problems with the IDs as I think there are then two columns named ID)
Quote Reply
Re: [afinlr] Last 10 reviews posted In reply to
Hi Laura,

Thanks a bunch. It works perfectly. I had put this in my template :
<%if Title%><%Title%><%else%>Read This Review<%endif%> followed by <%Review_Subject%> so that the subject gives an idea if I can't get the title but you were spot on.


Code:
sub {
my ($output,$hit);
my $table = $DB->table('Reviews','Links');
$table->select_options('ORDER BY Review_Date DESC','LIMIT 10');
# Only select validated reviews
my $sth = $table->select({Review_Validated => 'Yes'}) || return $GT::SQL::error;
while (my $hit = $sth->fetchrow_hashref()) {
# Modify short date format to mini format
$hit->{Review_Date}=GT::Date::date_transform($hit->{Review_Date},"%yyyy%-%mm%-%dd%","%dd% %mmm% %yy%");
$output .= Links::SiteHTML::display('newreviewsdate', $hit);
}
return $output;
}

Also in the Review table the review is identified by 'Review_ID' and the link it refers to is identified by 'Review_LinkID' so I'm guessing the conflict you were worried about shouldn't occur and hence your idea worked first time. Smile

Thanks for helping out.

I changed the third line to 'ORDER BY Review_Date DESC' instead of 'ORDER BY Review_Date','DESC' but I'm not quite sure how this affects things.Blush

Thanks again Laura, have a nice a day...

John
Significant Media
Quote Reply
Re: [Jag] Last 10 reviews posted In reply to
Hiya.

I'm trying to make use of this global, but having a little problem getting it to work. As far as I've understood reading forum posts and looking at examples, I should only need to add this to get it to display on a template page:

<%loop latest_reviews%>
<a href="<%URL%>"<%Title%></a>
<%endloop%>

Am I in the right ballpark, or am I totally off here?
Cheers,
Hans Jørgen
www.dicereviews.com
Quote Reply
Re: [perhaps] Last 10 reviews posted In reply to
Hi,

You need to add a global, called "load_latest_reviews" ..with the following code:

Code:
sub {
my ($output,$hit);
my $table = $DB->table('Reviews','Links');
$table->select_options('ORDER BY Review_Date DESC','LIMIT 10');
# Only select validated reviews
my $sth = $table->select({Review_Validated => 'Yes'}) || return $GT::SQL::error;
while (my $hit = $sth->fetchrow_hashref()) {
# Modify short date format to mini format
$hit->{Review_Date}=GT::Date::date_transform($hit->{Review_Date},"%yyyy%-%mm%-%dd%","%dd% %mmm% %yy%");
$output .= Links::SiteHTML::display('newreviewsdate', $hit);
}
return $output;
}

Then call with:

Code:
<%load_latest_reviews%>
<%if latest_reviews%>
<%loop latest_reviews%>
<a href="<%URL%>"<%Title%></a>
<%endloop%>
<%endif%>

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Last 10 reviews posted In reply to
I have already created the global that JAG posted and called it latest_reviews. I don't need both that one and the one you posted, right? (they looked the same at a quick glance) :)

I just need to change my template code to:

<%latest_reviews%>
<%if latest_reviews%>
<%loop latest_reviews%>
<a href="<%URL%>"<%Title%></a>
<%endloop%>
<%endif%>

Right?
Cheers,
Hans Jørgen
www.dicereviews.com
Quote Reply
Re: [perhaps] Last 10 reviews posted In reply to
Hi,

You need to rename your global then =)

At the moment, its accessing the global: <%latest_reviews%> ... and then returning the loop called exactly the same.

Try calling the global:

<%load_latest_reviews%>

..then call with:


Code:
<%load_latest_reviews%>
<%if latest_reviews%>
<%loop latest_reviews%>
<a href="<%URL%>"<%Title%></a>
<%endloop%>
<%endif%>

That should do the trick :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Last 10 reviews posted In reply to
Hmm. The build job just hangs on homepage now. (trying to add this to the homepage)

I'll explain everything I've done.

I've added the following global called load_latest_reviews

Code:
sub {
my ($output,$hit);
my $table = $DB->table('Reviews','Links');
$table->select_options('ORDER BY Review_Date DESC','LIMIT 5');
# Only select validated reviews
my $sth = $table->select({Review_Validated => 'Yes'}) || return $GT::SQL::error;
while (my $hit = $sth->fetchrow_hashref()) {
# Modify short date format to mini format
$hit->{Review_Date}=GT::Date::date_transform($hit->{Review_Date},"%yyyy%-%mm%-%dd%","%dd% %mmm% %yy%");
$output .= Links::SiteHTML::display('newreviewsdate', $hit);
}
return $output;
}


I then added the following code to a template page where I want to display the last 5 reviews:
Code:
<%load_latest_reviews%>
<%if latest_reviews%>
<%loop latest_reviews%>
<a href="<%URL%>"<%Title%></a>
<%endloop%>
<%endif%>

I'm sure I'm doing -something- wrong, just can't figure out what. :P
Cheers,
Hans Jørgen
www.dicereviews.com
Quote Reply
Re: [perhaps] Last 10 reviews posted In reply to
Hi,

Sorry, just realised the advice I gave you was rubbish <G>

You should be able to call it with just:

<%load_latest_reviews%> (which will output the reviews)

There shouldn't be any need for any of the loop:

Code:
<%if latest_reviews%>
<%loop latest_reviews%>
<a href="<%URL%>"<%Title%></a>
<%endloop%>
<%endif%>

(the loop is probably the reason its freezing =))

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Last 10 reviews posted In reply to
Hi again!

I changed the html to now only have this:

Code:

<%if load_latest_reviews%>
<%load_latest_reviews%>
<%endif%>

Which caused a freeze on build. And then without the if statement, which also caused a freeze. I think this was the first I tried when I found the global to be honest, and when I didn't get it to work, I tried with loop etc. Any ideas? Thanks for the help so far! :)
Cheers,
Hans Jørgen
www.dicereviews.com
Quote Reply
Re: [perhaps] Last 10 reviews posted In reply to
Hi,

You don't need the <%if ...%> bit :)

Literally just:

Code:
<%load_latest_reviews%>

If you still can't get it working, feel free to email/PM me over your GLinks admin panel details, and I'll have a quick look for you - should be something simple :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Last 10 reviews posted In reply to
Hi,

All sorted. The reason it wasn't working, was due to the newreviewdate.html template not existing =)

The simplest form, is to just put this code into it:

Code:
<%include review_include.html%>

Or if you don't want to make the new tempalte, you could just change:

Code:
$output .= Links::SiteHTML::display('newreviewsdate', $hit);

..to:

Code:
$output .= Links::SiteHTML::display('review_include', $hit);

Cool

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Last 10 reviews posted In reply to
Excellent stuff. As you can see, it's now displaying just fine on the homepage:
www.dicereviews.com

This initial post by Jag was started to fix implementing the <%title%> tag so that people can jump directly to the detailed page from the review. Any clues on how to implement it?
Cheers,
Hans Jørgen
www.dicereviews.com
Quote Reply
Re: [perhaps] Last 10 reviews posted In reply to
Hi,

For anyone interested, the final global was:

load_latest_reviews ==>

Code:
sub {
my ($output,$hit);
my $table = $DB->table('Reviews','Links');
$table->select_options('ORDER BY Review_Date DESC','LIMIT 5');
# Only select validated reviews
my $sth = $table->select({Review_Validated => 'Yes'}) || return $GT::SQL::error;
while (my $hit = $sth->fetchrow_hashref()) {
# Modify short date format to mini format
$hit->{Review_Date}=GT::Date::date_transform($hit->{Review_Date},"%yyyy%-%mm%-%dd%","%dd% %mmm% %yy%");
$hit->{detailed_url} = $CFG->{build_detail_url} . '/' . $DB->table('Links')->detailed_url($hit->{ID});
$output .= Links::SiteHTML::display('newreviewsdate', $hit);
}
return $output;
}

Called with:

<%load_latest_reviews%>

You also need a new template, called newreviewsdate.html, with the following content:

Code:
<a href="<%detailed_url%>#reviews"><%Title%></a> - <%Review_Subject%> (<%Review_Date%>) <br />

Enjoy =)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Last 10 reviews posted In reply to
How I make that this global return the last reviews per category and here subcategory
<%load_latest_reviews(caitid)%>
Quote Reply
Re: [nir] Last 10 reviews posted In reply to
Hi,

It took a bit of playing around - but this should work (did on my test install)

Code:
sub {
my ($output,$hit);

my $catid = $_[0];
my $all_ids = $DB->table('Category')->children($catid);
push @$all_ids, $catid;

my $table = $DB->table('Reviews','Links','Category','CatLinks');
$table->select_options('ORDER BY Review_Date DESC','LIMIT 5');

# Only select validated reviews
my $seen;
my $sth = $table->select( GT::SQL::Condition->new( ['CategoryID', 'IN', $all_ids], [ 'Review_Validated', '=', 'Yes' ] ) ) || return $GT::SQL::error;
while (my $hit = $sth->fetchrow_hashref()) {
# Modify short date format to mini format
if ($seen->{$hit->{Review_LinkID}}) { next; }
$seen->{$hit->{Review_LinkID}};
$hit->{Review_Date}=GT::Date::date_transform($hit->{Review_Date},"%yyyy%-%mm%-%dd%","%dd% %mmm% %yy%");
$hit->{detailed_url} = $CFG->{build_detail_url} . '/' . $DB->table('Links')->detailed_url($hit->{ID});
$output .= Links::SiteHTML::display('newreviewsdate', $hit);
}

return $output;
}

Call with:

<%load_latest_reviews($ID)%>

..(where $ID is the category ID)

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!

Last edited by:

Andy: Jan 28, 2008, 5:31 AM
Quote Reply
Re: [Andy] Last 10 reviews posted In reply to
Thanks Andy, for some reason it return the same reviews more than one time.
Quote Reply
Re: [nir] Last 10 reviews posted In reply to
Hi,

Mmm.. really?

Do you have an example?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Last 10 reviews posted In reply to
I understand what the problem is, it return the review in every category that the link is submit. So it I have link in 3 sub category I get the review 3 times.
Quote Reply
Re: [nir] Last 10 reviews posted In reply to
Hi,

Please try the modified version here: http://www.gossamer-threads.com/...?post=300153#p300153

Hopefully that will solve the problem :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Last 10 reviews posted In reply to
ThanksLaugh
Quote Reply
Re: [nir] Last 10 reviews posted In reply to
Hi,

No problem =)

I think I may add this to my ULTRAGlobals plugin too - as its quite a cool global now <G> (much better than just the basic "latest reviews" global that I have in that plugin already).

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Last 10 reviews posted In reply to
Andy wrote:
I think I may add this to my ULTRAGlobals plugin too

Hi Andy, that's a good idea :-))

Thanks
Matthias

Matthias
gpaed.de