View Full Version : Wordpress - again and again?
TheRedRose
01-06-2007, 12:08 PM
Hello,
okay, first, I have searched the forum over and over, searched via google and every page i found for a solution but nothing...
I want to:
Show the, lets say, last 5 posts (just the title with link) from my wordpress blog on my pixelpost blog (in a <div>). That's it.
I want to keep them seperate, I'm showing the latest thumb from pixelpost in my wordpress blog, this was no problem because I found a plugin for that.
And now I want to link from pp to wp, I found a code in a forum that looks like this:
<?php
$posts = get_posts("numberposts=5");
if( $posts ) :?>
<div style="position:absolute; left:50px; top:140px;">
test
<h4>Recent News »</h4>
<ul>
<?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
<?php
$even_odd = ( 'odd' != $even_odd ) ? 'odd' : '';
?>
<li class="<?php echo $even_odd; ?>"><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
But somehow I can't get it to work, I tried creating an addon myself but It didn't work...
Any ideas??
Thx in advance
Sebastian
austriaka
01-06-2007, 01:46 PM
Is there an error message? What does it tell?
Where is the function get_posts() defined?
You will have to include the file where this function is performed as well as the other functions: setup_postdata(), the_permalink(), the_title()
If Wordpress uses the same database as pixelpost, a more easy way is to pull them directly out of the database wordpress tables:
$wp_post = mysql_query("SELECT {_TITLE_}, {_PERMALINK} FROM {_WORDPRESS_POST_TABLE_} ORDER BY {_DATE_AND_TIME_} desc limit 0,5");
Replace the strings between {} with the correct table field names resp. with the table name of your wordpress post table.
while(list($title, $permalink) = mysql_fetch_row($wp_post)) {
echo '<li><a href="'.$permalink.'" title="Permanent Link to '.$title.'">'.$title.'</a></li>';
}
HTH
KArin
TheRedRose
01-08-2007, 11:00 AM
Can it be that easy? and I think I forgot to add something :)
The wordpress functions are defined in a file that I include
<?php require('../wordpress/wp-header.php'); ?>
Worpress and Pixelpost use different databases and are located in different directories on the server.
But I think the main problem is how to call the wordpress functions correctly..
If I call the php-functions in a pixepost-template-html-file, nothing happens.. (?)
I wrote an addon and as soon as I try to call the first function
$posts = get_posts('numberposts=5');
the script fails.
I have no idea why, as it should be possible to call wordpress function from other pages..
Thx for the help :)
Connie
01-08-2007, 11:04 AM
Why don't use the feed of your WordPress? I am sure Wordpress has RSS-feed?
use that functionality, I am sure it exists
http://codex.wordpress.org/WordPress_Feeds
you could link to your feed in the PP-template
TheRedRose
01-08-2007, 11:08 AM
I thought about that too..
I'll give it a try, if I find some information on how to read rss-feeds using php of course :)
thx
austriaka
01-08-2007, 11:11 AM
the script fails
what is the error / failure message?
KArin
TheRedRose
01-08-2007, 11:28 AM
There is no error message (or at last none I can read), the page simply does not load as the faulty addon halts the complete pixelpost execution.
If I use the php in the template it is simply not executed the page loads normaly but without any effect..
austriaka
01-08-2007, 11:33 AM
The not loading page points to some script error in your PHP.
Perhaps you could post the code here?
Try to use "include" instead of require and/or use the Server path instead of a relative path.
I can see no reason why this should not work...
KArin
TheRedRose
01-08-2007, 11:52 AM
I can see no reason why this should not work...
Me too :)
Here is the complete :rolleyes: code of my addon, there is nothing in there except include() and the function call, which fails.
<?php
$cnt='';
....
include('../wordpress/wp-header.php');
$posts = get_posts('numberposts=5');
...
$tpl = ereg_replace("<LATEST_WORDPRESS>",$cnt,$tpl);
I'm trying to read the rss-feed for now, this seems to be much easier as I don't have to worry about multiple database querys and server load :)
austriaka
01-08-2007, 11:59 AM
have you tried to "echo-out" each line of your admin?
IE
echo $posts;
echo $cnt;
immediately after variable is filled.
This should show you where the error is...
KArin
TheRedRose
01-08-2007, 12:16 PM
I "know" where the error is.
The wordpress function itself get_posts() does not work.
If I delete the function-call in then addon it loads and executes, if I insert it, the execution fails.
I know how to write addons, I know how to write php and how to track errors... I just don't know why the function call fails :rolleyes:
No offense, I'm very thankful for you trying to help me ;)
dakwegmo
01-08-2007, 03:31 PM
No matter what I tried, I couldn't get my PP thumbnails to show up in Wordpress. Both sites are hosted on the same server, but even a hard coded image tag with the url of the latest thumbnails didn't work either. I finally installed one of the RSS widgets to pull my last five thumbnails from PP, and that worked. If you figure out why it doesn't work, I'd be curious to find out myself. If you don't really care about why, and just want it to work, I'd recommend looking into the Sidebar Widgets Plugin, and one of the RSS widgets.
You can see what I did on my site here www.dakwegmo.com.
Dennis
01-08-2007, 05:56 PM
Hmm... I have the latest thumbnail showing on my blog. Just a matter of some PHP and a query to the database.
(Blog can be found @ http://www.schonhose.nl )
The code is quite easy...
TheRedRose
01-09-2007, 11:50 PM
Yeah, well I have that, too :) But I must say, you fused both worlds very well :)
But I wanted it the other way round and I want to keep them seperate (for now)
I finally solved the problem accessing the rss-feed as suggested by Connie (thx :D)..
I used SimplePIE to access the feed, it was very, very, very easy :cool:
If anyone is interested, here is the code I wrote (very simple, but works great)
require('../php/simplepie.inc');
$cnt='';
$feed = new SimplePie();
$feed->feed_url('http://www.theredrose.de/wordpress/?feed=rss2');
$feed->cache_location('../cache');
$feed->init();
$feed->handle_content_type();
if ($feed->data)
{
$cnt='<div id="latestwordpress">';
$cnt.='<h4>latest blog entrys (de)</h4>';
$cnt.='<!--'.$feed->get_feed_title().'-->';
$max = $feed->get_item_quantity(5);
for ($x = 0; $x < $max; $x++)
{
$item = $feed->get_item($x);
$cnt .= '<a href=" '.$item->get_permalink().' ">'.$item->get_title().'</a>';
if ($x<($max-1))
{ $cnt.='<HR COLOR=#999 WIDTH=50%>'; }
else
{ $cnt.='<br><br>';}
}
$cnt.='</div>';
}
$tpl = ereg_replace("<LATEST_WORDPRESS>",$cnt,$tpl);
You can see it in action on my pp-page (look at my signature below)
Dennis
01-10-2007, 05:36 AM
Yeah, well I have that, too :) But I must say, you fused both worlds very well :)
Thanks, it surely helps to have a deep insight in the pixelpost code ;)
vBulletin® v3.7.3, Copyright ©2000-2013, Jelsoft Enterprises Ltd.