I am attempting to display the latest 3 posts from my blog, On my Opencart site.
The WP blog is at a subdomain blog.domain.com
I am adding this to footer.tpl in OC
<?php
require('/var/www/vhosts/blog.domain.com/wp-blog-header.php');
?>
But when i do this i get this error...
Notice: Constant DB_PASSWORD already defined in /var/www/vhosts/blog.domain.com/wp-config.php on line 29 Warning: mysql_connect(): Access denied for user '<>'@'localhost' (using password: YES) in /var/www/vhosts/blog.domain.com/wp-includes/wp-db.php on line 1036
From what i have been reading this is being caused by having 2 DB_PASSWORD defined, assuming that these would be 1 for WP and 1 for OC.
Is there anyway to work around this?
To anyone that is looking for the answer to this later as @sammitch suggested using the RSS feed is a great way to do this here is a code snippet below.
<?php
$rss = new DOMDocument();
$rss->load('<<URL TO RSS FEED>>');
$feed = array();
foreach ($rss->getElementsByTagName('item') as $node) {
$item = array (
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
);
array_push($feed, $item);
}
$limit = 3;
for($x=0;$x<$limit;$x++) {
$title = str_replace(' & ', ' & ', $feed[$x]['title']);
$link = $feed[$x]['link'];
echo '<li><a href="'.$link.'" title="'.$title.'" target="_blank">'.$title.'</a></li>';
}
?>
Probably worth mentioning that i only needed title and link from the array there is a lot of other variables that you can pull out.