Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Latest posts from wordpress on home.html

(Page 1 of 2)
> >
Quote Reply
Latest posts from wordpress on home.html
Hi,
does anyone know how to show the latest post from wordpress in glinks home.html.
The wordpress install has the same domain but a different database!

Thanks
Matthias

Matthias
gpaed.de
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!
Quote Reply
Re: [Andy] Latest posts from wordpress on home.html In reply to
Hi Andy,
perfect, I have an output, there is only one problem.
I set output to 5 posts, but the post are all the same.
I see the last post 5 times?

Thanks
Matthias

Matthias
gpaed.de
Quote Reply
Re: [Matthias70] Latest posts from wordpress on home.html In reply to
Can you post a link, or PM me a link if you don't want to make it public yet?

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

Can you please change:

Code:
my $query = qq|SELECT * FROM ${prefix}posts ORDER BY ID DESC LIMIT 10|;


...to:

Code:
my $query = qq|SELECT * FROM ${prefix}posts WHERE post_parent < 1 ORDER BY ID DESC LIMIT 10|;

That should sort it =)

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
Hi Andy,
this one is working fine

The urls are different from my permanent link setup, but I it's fine the way it is.
Thank you Andy

Matthias
gpaed.de
Quote Reply
Re: [Matthias70] Latest posts from wordpress on home.html In reply to
Hi Andy,
is there a way to cut of the time of the post date. I just need the date not the time...
Thanks

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

Glad its working

You could try changing:

<%post_date%>

..to:

<%get_just_date($post_date)%>

..and a new global: get_just_date

Code:
sub {
my @tmp = split / / , $_[0];
return $tmp[0]
}

That should do it Smile

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
Hi Andy,
thanks but I just cut off date and time. Cause I don't need both of them.
Thanks for your help, again

Matthias
gpaed.de
Quote Reply
Re: [Matthias70] Latest posts from wordpress on home.html In reply to
Hi Andy,
I just realized that this global shows draft posts as well?
Is there a way to show only published posts?

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

Try changing:

Code:
my $query = qq|SELECT * FROM ${prefix}posts WHERE post_parent < 1 ORDER BY ID DESC LIMIT 10|;

..to:

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

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
Hi Andy,
works perfect
Thanks

Matthias
gpaed.de
Quote Reply
Re: [Matthias70] Latest posts from wordpress on home.html In reply to
Hi Andy,
is there a way to show the latest comments from wordpress in glinks home.html.
The wordpress install has the same domain but a different database!

Thanks


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

Not sure from the top of my head. I'm still a bit busy (and feeling like crap with a horrible cold :() - but remind me in a couple of days, and I'll see if I can have a look.

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
How to pull posts from a particular category of wordpress?

thanks.
Quote Reply
Re: [hegu] Latest posts from wordpress on home.html In reply to
Sorry, not got a copy of Wordpress available (so I could look at the table structure), so not sure I can help :(

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:
Sorry, not got a copy of Wordpress available (so I could look at the table structure), so not sure I can help :(

Cheers

Hi Andy, what is going on. Isn't a wordpress installation a must have in these days Wink

By the way, do you know how to change the global above to show the latest 10 comments?
May be it's only one different line of code?

Thanks

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

LOL - I'm not a big fan of blogging to be honest (never have enough time to do it :P)

Re the code change - are you wanting to grab the actual comments (not blogs), to show them? If so, shouldn't be too hard - again though, I don't have an installation of WP, so can't see the DB structure.

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
Hi Andy,
here is the code I'm using for the latest 5 wordpress post.
I marked the post related parts in red

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}posts WHERE post_parent < 1 AND post_status = 'publish' ORDER BY ID DESC LIMIT 5|;

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 }

}


Code:
<%latest_wordpress%>
<%if blog_loop.length%>
<%loop blog_loop%>
<p><b><a href="<%guid%>"><%post_title%></a></b><br />
<%endloop%>

I have sent you a gif attachment with the wordpress database field for the comments
Perhaps you can tell me the important field, so I can play around a little bit...

Matthias
gpaed.de
Quote Reply
Re: [Matthias70] Latest posts from wordpress on home.html In reply to
Wild stab in the dark, but try:
get_latest_comments
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) {
push @loop, $hit;
}

$sth->finish();
$dbh->disconnect();

return { get_latest_comments => \@loop }

}



Code:
<%get_latest_comments%>
<%loop get_latest_comments%>
...loop the value stuff here
<%endloop%>

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
Hi Andy,
O.K. now I have an output.
Have a look at http://www.gpaed.de/g-comments

But I have two problems.
1. I have no access to the post title and the post url, which should be on top of the comment content.
2. I don't want to display the whole comment, just a few words?


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 5|;

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 { latest_wordpress_comments => \@loop }

}

Code:
<%latest_wordpress_comments%>
<%loop latest_wordpress_comments%>
<p><a href="<%guid%>"><%comment_content%></a><br />
<%endloop%>

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

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!
Quote Reply
Re: [Andy] Latest posts from wordpress on home.html In reply to
Hm the field names are O.K
but now I get an internal server error :-(

Matthias
gpaed.de
Quote Reply
Re: [Matthias70] Latest posts from wordpress on home.html In reply to
Do you have an error log? If so, that does it say?

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

Try this one (there were a couple of issues with the last global)

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 $post_id = $_[0];
my $sth = $dbh->prepare(qq|SELECT post_title FROM ${prefix}posts WHERE post_id = $post_id|) || die $DBI::errstr;
$sth->execute() || die $DBI::errstr;
return $sth->fetchrow;
}

}

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!
> >