You probably want <%comment_post_ID%> for the post ID (not sure how you link it to WP, but that should be enough to do so)
You would need to somehow get the blog post title from the "wp_post" table, but without knowing the field names, wouldn't be able to help you there. Should be as simple as something like:
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 { get_latest_comments => \@loop }
sub get_title {
my $sth = $dbh->prepare(qq|SELECT post_title FROM ${prefix}posts WHERE post_id = $_[0]|) || die $DBI::errstr;
$sth->execute() || die $DBI::errstr;
return sth->fetchrow;
}
}
Cheersw
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:
1. I have no access to the post title and the post url, which should be on top of the comment content.You would need to somehow get the blog post title from the "wp_post" table, but without knowing the field names, wouldn't be able to help you there. Should be as simple as something like:
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 { get_latest_comments => \@loop }
sub get_title {
my $sth = $dbh->prepare(qq|SELECT post_title FROM ${prefix}posts WHERE post_id = $_[0]|) || die $DBI::errstr;
$sth->execute() || die $DBI::errstr;
return sth->fetchrow;
}
}
Cheersw
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!