Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Latest posts from wordpress on home.html

(Page 2 of 2)
> >
Quote Reply
Re: [Andy] Latest posts from wordpress on home.html In reply to
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?

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
Quote Reply
Re: [Matthias70] Latest posts from wordpress on home.html In reply to
Hi,

Glad it works.

Regarding trimming the comments, just give my "Trim" function from ULTRAGlobals a go- that should work fine for what you need.

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] Latest posts from wordpress on home.html In reply to
Great, the trim function works with data from wordpress, too :-)
Here is how I call the above global.
Code:
<%latest_wordpress_comments%>
<%loop latest_wordpress_comments%>
<small><a href="http://www.gpaed.de/blog/?p=<%comment_post_ID%>/#comment-<%comment_ID%>"><%comment_author%></a> schrieb zu <a href="http://www.gpaed.de/blog/?p=<%comment_post_ID%>"><%post_title%></a><br /><%Plugins::ULTRAGlobals::Trim_Field(0,100,$comment_content)%></small><br /><br />
<%endloop%>

Thanks for your help.
I will paypal you in a few minutes

Matthias
gpaed.de
Quote Reply
Re: [Matthias70] Latest posts from wordpress on home.html In reply to
Hi Andy,
I was using the code for years now. But after changing the wordpress template.
The code does not show the last new wordpress entries...
It shows links to two pages. But even this links are wrong!?!
Do you have a idea why?

Code:
sub {
my $prefix = 'wp_';

use DBI;
my $dbh = DBI->connect('DBI:mysql:xxxxxxxx', 'xxxxxxxx', 'xxxxxxxx'
) || die "Could not connect to database: $DBI::errstr";


my $query = qq|SELECT * FROM ${prefix}posts WHERE post_parent < 1 AND post_status = 'publish' ORDER BY ID DESC LIMIT 3|;

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 }

}

Thanks

Matthias
gpaed.de
Quote Reply
Re: [Matthias70] Latest posts from wordpress on home.html In reply to
What happens if you run the query manually in mysqlman/phpmyadmin?

i.e

Code:
SELECT * FROM wp_posts WHERE post_parent < 1 AND post_status = 'publish' ORDER BY ID DESC LIMIT 3

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] Latest posts from wordpress on home.html In reply to
Andy wrote:
What happens if you run the query manually in mysqlman/phpmyadmin?

i.e

Code:
SELECT * FROM wp_posts WHERE post_parent < 1 AND post_status = 'publish' ORDER BY ID DESC LIMIT 3


Cheers

This code shows at the moment the last new pages. When I'm posting the next new articles, they will be shown instead. Should be everything O.K. when I'm posting a few more articles ;-)

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

So its ok now?

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] Latest posts from wordpress on home.html In reply to
Andy wrote:
Hi,

So its ok now?

Cheers

Do you know an easy workaround for excluding pages and only showing articles?
Otherwise it's O.K. Wink

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

You could try adding this into the query:

Code:
AND post_type = "post"

i.e:

Code:
my $query = qq|SELECT * FROM ${prefix}posts WHERE post_parent < 1 AND post_status = 'publish' AND post_type = "post" ORDER BY ID DESC LIMIT 3|;

Not 100% sure thats right - but having a quick look that seems like it matches Angelic

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] Latest posts from wordpress on home.html In reply to
Cool, it's working fine Smile
Thanks

Matthias
gpaed.de
> >