Fishpig获得最新3篇博客文章

时间:2016-04-25 14:18:25

标签: php wordpress blogs fishpig

任何人都可以向我提供一些代码,这些代码将使用Fishpig扩展程序从Magento中的Wordpress获取最后3篇博文。无法找到可在任何地方使用的模板。需要抓住博客标题,内容和特色图片。

我相信我到目前为止走错了路。

<?php $resource = Mage::getSingleton('core/resource');
   $readConnection = $resource->getConnection('core_read');
   $query = "SELECT p.id,p.post_title,p.post_name ,p.post_content,p.comment_count,pm.meta_value FROM wp_postmeta AS pm INNER JOIN wp_posts AS p ON pm.post_id=p.ID  ORDER BY p.post_date";
   $results = $readConnection->fetchAll($query);


   ?>
<?php 
   foreach($results as $row) { ?>
<?php if($row['post_title']!='Auto Draft'):  
   //Get url from pm.meta_value
   /********/
   $readConnection1 = $resource->getConnection('core_read');
   $query1 ="SELECT * FROM `wp_postmeta` WHERE `post_id` = '".$row['meta_value']."' AND meta_key='_wp_attached_file'"; 
   $results1 = $readConnection->fetchAll($query1);
   $url='/news/wp-content/uploads/'.($results1[0]['meta_value']);
   ?>
<div class="blog-post-image">
   <img src="<?php echo $url; ?>">
</div>
<div class="blog-post-content">
   <?php  ?>
   <h3> <a href="<?php echo $this->getUrl('news/').$row['post_name'];?>"> <?php echo $row['post_title'];?></a></h3>
   <p class="blog-content">  <?php $content = $row['post_content'];  echo $string = substr($content,0,220); if(strlen($content)>220){echo "...";}      ?></a></p>
   <a href="" class="blog-posts-cta">More Info</a>
</div>
<?php endif; ?>
<?php
   if($counter == 4)
   {
        break;
   }
   $counter++;   
   }


?>

感谢。

0 个答案:

没有答案
相关问题