Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
240 views
in Technique[技术] by (71.8m points)

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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> 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...