Connect WordPress and Joomla

You want display a few Blogentries of your WordPress blog, can also be any other Blog, where you have query rights to? Then continue reading. It’s in just five minutes done!

As beginning we need to find out where wordpress stores the blog entries. The entries are saved in the table preposts Where pre is replaced with the prefix your table got from you. Now we get to the coding part.
We need to place into the header part of your template index.php file this code:

<?php
//Code to create The Newsfeed
print (‘<script language=”Javascript”><!–‘.”\n”);
print (‘v_content=[‘);$tablename = “preposts”;//replace it with your wordpress prefix
$query = “SELECT ID, guid, post_title, post_content, date_FORMAT(post_date_gmt, ‘%a %d %b <br /> \at %r’)AS Datum
FROM $tablename WHERE `post_status`=’publish’ ORDER BY post_date_gmt DESC LIMIT 0,4”;
//selects and return the first 4 published entries, you can also change the number to more
$result = mysql_query($query)Or die(“Query<pre>$query</pre> Error: “.mysql_error());if (mysql_num_rows($result)){
for ($i=1;$i<=4;$i++)
{
$row=mysql_fetch_assoc($result);
print (“[‘$row[guid]’,'<strong><font style=\”font-size:9pt\”>”.str_replace(“‘”,”‘”,$row[post_title]).”</font></strong><br />

<font style=\”font-size:7pt\”>Posted on $row[Datum]</font><br />’,’_blank’]”);
if ($i<4) print (“,\n);
}//returns the headings and a line under it the date when it was published
}
print (‘];’);
print (‘//–></script>’);
?>

The printing part is build up in this way: [‘LINK to’,’Text to display’,’NeworSame Window’]
Between these Items you need to put a , and all together are between [].

That’s already everything we need for the header part.
Now we need to let it be showed, therefor we simply add another script part in the part where we want to show it. To display it for my theme where the Newsfeed is it would be need to be within the bold:

<div id=”top_outer”>
<div id=”top_inner”>
<?php
if ( mosCountModules( ‘top’ ) ) {
mosLoadModules ( ‘top’ );

/*code to show the blog entries,*/ print(‘<script language=”JavaScript1.2″ xsrc=”newsflash.js”></script>’);
print(‘<a xhref=”http://blog.phsoftware.de”>More at PSB-Blog&lt/a>’);/*end of showing code*/

} else {
?> <span class=”error”>Top Module Empty</span> <?php
}
?>
</div>
</div>

You see we need some extern javascript file, the file can be found here for free use. You just need to put it into your joomla root. And that’s all you need.

About Lejer

Blog.Lejer.ro Admin
This entry was posted in Main. Bookmark the permalink.