如何在自定义PHP文件中包含Wordpress帖子? [英] How can I include Wordpress posts in a custom PHP file?
本文介绍了如何在自定义PHP文件中包含Wordpress帖子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这就是我想要做的:
我希望/summary.php
在我的博客中包含5个最新帖子(仅摘录),这些帖子位于/wp
中.
I want /summary.php
to include 5 latest posts (only the extract) from my blog, which lives in /wp
.
有什么方法可以在/summary.php
中包括Wordpress并仅打印这些帖子的html? (也许我应该解析rss?)
Is there any way to include Wordpress in /summary.php
and only print the html for these posts? (Maybe i should parse the rss?)
推荐答案
这是该页面上的示例,以字母顺序显示前十个帖子:
This is an example from that page, that shows the first ten posts in alphabetical order:
<?php
require('/the/path/to/your/wp-blog-header.php');
?>
<?php
$posts = get_posts('numberposts=10&order=ASC&orderby=post_title');
foreach ($posts as $post) : start_wp(); ?>
<?php the_date(); echo "<br />"; ?>
<?php the_title(); ?>
<?php the_excerpt(); ?>
<?php
endforeach;
?>
如果要更新10篇最新文章,请使用$posts = get_posts('numberposts=10');
.
Use $posts = get_posts('numberposts=10');
if you want the 10 latest posts.
这篇关于如何在自定义PHP文件中包含Wordpress帖子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文