How to get posts' content as HTML from a wordpress blog remotely

孤街醉人 提交于 2019-12-24 22:48:17

问题


I have self-hosted word-press Blog, and I am making a static home-page for my website based on jQuery. So, I wanted to display some content from my blog , in my home page ( in widgets ) , as a news section

For example , I may fetch

  • latest 5 posts titles & contents
  • OR a specific page content ( via passing page id )
  • OR a specific post ( via passing post id )

So does Wordpress include any PHP file , that shows the posts contents as plain text, or HTML ??

I thought about fetching the Blog's RSS , then show it on the page,
but the RSS doesn't provide the full content of the post.

Thanks in advance


回答1:


If it's hosted on the same server, you could integrate wordpress into your app by including wp-blog-header.php, and then call get_posts(), using setup_postdata().

For example:

 <ul>
 <?php
 global $post;
 $tmp_post = $post;
 $myposts = get_posts('numberposts=5&offset=1&category=1');
 foreach($myposts as $post) :
   setup_postdata($post);
 ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
 <?php endforeach; ?>
 <?php $post = $tmp_post; ?>
 </ul> 



回答2:


Take a look at Yahoo! Pipes.



来源:https://stackoverflow.com/questions/3572027/how-to-get-posts-content-as-html-from-a-wordpress-blog-remotely

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!