如何从 wordpress 博客远程获取 HTML 形式的帖子内容 [英] How to get posts' content as HTML from a wordpress blog remotely
问题描述
我有自托管的 word-press 博客,我正在为我的网站基于 jQuery 制作一个静态主页.所以,我想在我的主页(在小部件中)显示我博客中的一些内容作为新闻部分
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
例如,我可以获取
- 最新的 5 个帖子标题和内容
- OR 特定页面内容(通过传递页面 ID)
- 或特定帖子(通过传递帖子 ID)
Wordpress 是否包含任何将帖子内容显示为纯文本或 HTML 的 PHP 文件??
So does Wordpress include any PHP file , that shows the posts contents as plain text, or HTML ??
我想过获取博客的RSS,然后显示在页面上,
但 RSS 没有提供帖子的全部内容.
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.
提前致谢
推荐答案
如果它托管在同一台服务器上,您可以通过包含 wp-blog-header.php
将 wordpress 集成到您的应用程序中,然后调用 get_posts(),使用 setup_postdata()
.
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()
.
例如:
<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>
这篇关于如何从 wordpress 博客远程获取 HTML 形式的帖子内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!