如何使用fishpig wordpress集成扩展在Magento主页上显示单个帖子的详细信息?

时间:2016-10-10 05:16:48

标签: magento-1.9 fishpig

我已经在我的Magento网站上安装了fishpig WordPress集成,我想在我的Magento主页上使用静态块(带有帖子ID)显示单个帖子的详细信息。 所以请帮忙。

1 个答案:

答案 0 :(得分:2)

在模板中创建自定义.phtml文件并调用此

<!doctype html>
<html>
<head>



<meta charset="UTF-8">
<title>API TEST JSON</title>
</head>

<body>
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
	$place = "capetown,za";
	$json_string = file_get_contents("http://api.openweathermap.org/data/2.5/weather?q=$place&units=metric&APPID=API-KEY-GOES-HERE");
	$parsed_json = json_decode($json_string);
	$country = $parsed_json->sys->country;
	$wind = $parsed_json->wind->speed;
	$city = $parsed_json->name;
	$temp = $parsed_json->main->temp;
	$clouds = $parsed_json->weather[0]->description;
	if($clouds == "clear sky"){
		echo ("<img src='http://placehold.it/200x200'>");
	}
?>

<table border="1px solid black">
<tr>
<td style="color:red;">Country</td>
<td style="color:red;"><?php echo $country;?></td>
</tr>
<tr>
<td style="color:red;">City</td>
<td style="color:red;"><?php echo $city;?></td>
</tr>
<tr>
<td style="color:red;">Temperature</td>
<td style="color:red;"><?php echo $temp;?></td>
</tr>
<tr>
<td style="color:red;">Wind Speed M/S</td>
<td style="color:red;"><?php echo $wind;?></td>
</tr>
<tr>
<td style="color:red;">Cloudiness</td>
<td style="color:red;"><?php echo $clouds;?></td>
</tr>
</table>
</body>
</html>

在此之后,您可以在cms主页中调用.phtml文件。之后,使用以下命令在主页上调用静态块:

<?php
$data=Mage::getModel('wordpress/post')->getCollection()->setOrderByPostDate()->addIsPublishedFilter()->addPostTypeFilter(array('post'))->setPageSize(1);
?>
<div id="learn">
<ul class="xyzs" id="carousel1">
<?php $i = 0; foreach ($data as $post){
{
?>
<li class="item">
<?php if ($featuredImage = $post->getFeaturedImage()){ ?>
<div class="custom-image"><img alt="" src="<?php echo $featuredImage->getAvailableImage(); ?>"/></div>
<?php } ?>
<div class="learn_pragrap">
<span class="custom-date"><?php echo $post->getPostDate(); ?></span>
<h2><?php echo $post->getPostTitle(); ?></h2>
<p> <?php echo substr($post->getPostExcerpt(),0,149); ?> </p>
<div class="buttons-set">
<a class="button posts" title="Learn More" href="<?php echo $post->getPermalink() ?>"><span><span>View Full Story</span></a>
</div>
</div>
</li>
<?php //} $i++;

} ?>
  </ul>
</div>