Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Re: [Matthias70] Latest posts from wordpress on home.html

Quote Reply
Re: [Matthias70] Latest posts from wordpress on home.html In reply to
Hi,

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!
Subject Author Views Date
Thread Latest posts from wordpress on home.html Matthias70 24141 Jul 20, 2008, 1:30 AM
Thread Re: [Matthias70] Latest posts from wordpress on home.html
Andy 23522 Jul 20, 2008, 2:36 AM
Thread Re: [Andy] Latest posts from wordpress on home.html
Matthias70 23541 Jul 20, 2008, 2:54 AM
Post Re: [Matthias70] Latest posts from wordpress on home.html
Andy 23480 Jul 20, 2008, 2:54 AM
Thread Re: [Matthias70] Latest posts from wordpress on home.html
Andy 23468 Jul 20, 2008, 6:30 AM
Thread Re: [Andy] Latest posts from wordpress on home.html
Matthias70 23437 Jul 20, 2008, 8:11 AM
Thread Re: [Matthias70] Latest posts from wordpress on home.html
Matthias70 23465 Jul 20, 2008, 8:15 AM
Thread Re: [Matthias70] Latest posts from wordpress on home.html
Andy 23456 Jul 20, 2008, 9:04 AM
Thread Re: [Andy] Latest posts from wordpress on home.html
Matthias70 23449 Jul 20, 2008, 9:50 AM
Thread Re: [Matthias70] Latest posts from wordpress on home.html
Matthias70 23480 Jul 29, 2008, 6:53 AM
Thread Re: [Matthias70] Latest posts from wordpress on home.html
Andy 23389 Jul 29, 2008, 7:57 AM
Thread Re: [Andy] Latest posts from wordpress on home.html
Matthias70 23461 Jul 29, 2008, 8:12 AM
Thread Re: [Matthias70] Latest posts from wordpress on home.html
Matthias70 23435 Oct 16, 2008, 2:30 AM
Thread Re: [Matthias70] Latest posts from wordpress on home.html
Andy 23418 Oct 16, 2008, 2:32 AM
Thread Re: [Andy] Latest posts from wordpress on home.html
hegu 23121 May 17, 2009, 6:54 AM
Thread Re: [hegu] Latest posts from wordpress on home.html
Andy 23154 May 17, 2009, 9:00 AM
Thread Re: [Andy] Latest posts from wordpress on home.html
Matthias70 23093 May 17, 2009, 11:55 AM
Thread Re: [Matthias70] Latest posts from wordpress on home.html
Andy 23128 May 17, 2009, 11:36 PM
Thread Re: [Andy] Latest posts from wordpress on home.html
Matthias70 23166 May 18, 2009, 9:54 AM
Thread Re: [Matthias70] Latest posts from wordpress on home.html
Andy 23110 May 18, 2009, 10:03 AM
Thread Re: [Andy] Latest posts from wordpress on home.html
Matthias70 23026 May 18, 2009, 10:32 AM
Thread Re: [Matthias70] Latest posts from wordpress on home.html
Andy 23072 May 18, 2009, 10:40 AM
Thread Re: [Andy] Latest posts from wordpress on home.html
Matthias70 23114 May 18, 2009, 10:57 AM
Post Re: [Matthias70] Latest posts from wordpress on home.html
Andy 22945 May 18, 2009, 11:52 PM
Thread Re: [Matthias70] Latest posts from wordpress on home.html
Andy 23018 May 18, 2009, 11:58 PM
Thread Re: [Andy] Latest posts from wordpress on home.html
Matthias70 9392 May 19, 2009, 9:51 AM
Post Re: [Matthias70] Latest posts from wordpress on home.html
Andy 9412 May 19, 2009, 9:53 AM
Thread Re: [Andy] Latest posts from wordpress on home.html
Matthias70 9392 May 19, 2009, 10:23 AM
Thread Re: [Matthias70] Latest posts from wordpress on home.html
Matthias70 8969 May 31, 2013, 3:50 AM
Thread Re: [Matthias70] Latest posts from wordpress on home.html
Andy 8926 May 31, 2013, 8:18 AM
Thread Re: [Andy] Latest posts from wordpress on home.html
Matthias70 8810 Jun 1, 2013, 1:35 AM
Thread Re: [Matthias70] Latest posts from wordpress on home.html
Andy 8780 Jun 1, 2013, 2:17 AM
Thread Re: [Andy] Latest posts from wordpress on home.html
Matthias70 8890 Jun 1, 2013, 2:29 AM
Thread Re: [Matthias70] Latest posts from wordpress on home.html
Andy 8775 Jun 1, 2013, 2:40 AM
Post Re: [Andy] Latest posts from wordpress on home.html
Matthias70 8804 Jun 1, 2013, 2:47 AM