Hi,
Well, it can be easy - I tend to use this kind of code:
get_blog_latest
my $prefix = 'wp_';
use DBI;
my $dbh = DBI->connect('DBI:mysql:DB_NAME', 'DB_USERNAME', 'DB_PASSWORD'
) || die "Could not connect to database: $DBI::errstr";
my $query = qq|SELECT * FROM ${prefix}posts ORDER BY ID DESC LIMIT 10|;
my $sth = $dbh->prepare($query) || die $DBI::errstr;
$sth->execute() || die $DBI::errstr;
my @loop;
while (my $hit = $sth->fetchrow_hashref) {
push @loop, $hit;
}
$sth->finish();
$dbh->disconnect();
return { blog_loop => \@loop }
}
Cange the DB_NAME, DB_USERNAME, DB_PASSWORD - and $prefix (if its not wp_)
Then, just call with:
<%if blog_loop.length%>
<ul>
<%loop blog_loop%>
<li> <a href="<%guid%>"><%post_title%></a> (<%post_date%>)</li>
<%endloop%>
</ul>
<%endif%>
You could also do it via the GT::SQL .def files (with a new folder, with details on the database for Wordpress) - however, I've found this the best solution - as it doesn't give any headaches when upgrading WP in the future =)
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!
Well, it can be easy - I tend to use this kind of code:
get_blog_latest
Code:
sub { my $prefix = 'wp_';
use DBI;
my $dbh = DBI->connect('DBI:mysql:DB_NAME', 'DB_USERNAME', 'DB_PASSWORD'
) || die "Could not connect to database: $DBI::errstr";
my $query = qq|SELECT * FROM ${prefix}posts ORDER BY ID DESC LIMIT 10|;
my $sth = $dbh->prepare($query) || die $DBI::errstr;
$sth->execute() || die $DBI::errstr;
my @loop;
while (my $hit = $sth->fetchrow_hashref) {
push @loop, $hit;
}
$sth->finish();
$dbh->disconnect();
return { blog_loop => \@loop }
}
Cange the DB_NAME, DB_USERNAME, DB_PASSWORD - and $prefix (if its not wp_)
Then, just call with:
Code:
<%get_blog_latest%> <%if blog_loop.length%>
<ul>
<%loop blog_loop%>
<li> <a href="<%guid%>"><%post_title%></a> (<%post_date%>)</li>
<%endloop%>
</ul>
<%endif%>
You could also do it via the GT::SQL .def files (with a new folder, with details on the database for Wordpress) - however, I've found this the best solution - as it doesn't give any headaches when upgrading WP in the future =)
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!