Hi Andy,
it's working fine.
test example at http://www.gpaed.de/g-comments
Just had to change post_id to ID (marked red)
Is there a way to cut off the <%comment_content%> after 50 signs?
my $prefix = 'wp_';
use DBI;
my $dbh = DBI->connect('DBI:mysql:******', '******', '******'
) || die "Could not connect to database: $DBI::errstr";
my $query = qq|SELECT * FROM ${prefix}comments ORDER BY comment_date DESC LIMIT 10|;
my $sth = $dbh->prepare($query) || die $DBI::errstr;
$sth->execute() || die $DBI::errstr;
my @loop;
while (my $hit = $sth->fetchrow_hashref) {
$hit->{post_title} = get_title($hit->{comment_post_ID});
push @loop, $hit;
}
$sth->finish();
$dbh->disconnect();
return { latest_wordpress_comments => \@loop };
sub get_title {
my $ID = $_[0];
my $sth = $dbh->prepare(qq|SELECT post_title FROM ${prefix}posts WHERE ID = $ID|) || die $DBI::errstr;
$sth->execute() || die $DBI::errstr;
return $sth->fetchrow;
}
}
<%loop latest_wordpress_comments%>
<p><a href="http://www.gpaed.de/blog/?p=<%comment_post_ID%>"><%post_title%></a><br /><small><%comment_content%></small>
<%endloop%>
Thanks
Matthias
gpaed.de
it's working fine.
test example at http://www.gpaed.de/g-comments
Just had to change post_id to ID (marked red)
Is there a way to cut off the <%comment_content%> after 50 signs?
Code:
sub { my $prefix = 'wp_';
use DBI;
my $dbh = DBI->connect('DBI:mysql:******', '******', '******'
) || die "Could not connect to database: $DBI::errstr";
my $query = qq|SELECT * FROM ${prefix}comments ORDER BY comment_date DESC LIMIT 10|;
my $sth = $dbh->prepare($query) || die $DBI::errstr;
$sth->execute() || die $DBI::errstr;
my @loop;
while (my $hit = $sth->fetchrow_hashref) {
$hit->{post_title} = get_title($hit->{comment_post_ID});
push @loop, $hit;
}
$sth->finish();
$dbh->disconnect();
return { latest_wordpress_comments => \@loop };
sub get_title {
my $ID = $_[0];
my $sth = $dbh->prepare(qq|SELECT post_title FROM ${prefix}posts WHERE ID = $ID|) || die $DBI::errstr;
$sth->execute() || die $DBI::errstr;
return $sth->fetchrow;
}
}
Code:
<%latest_wordpress_comments%> <%loop latest_wordpress_comments%>
<p><a href="http://www.gpaed.de/blog/?p=<%comment_post_ID%>"><%post_title%></a><br /><small><%comment_content%></small>
<%endloop%>
Thanks
Matthias
gpaed.de