从wordpress博客添加“Recent Posts”到html静态页面
问题描述:
我正在开发一个新项目,我的客户需要一个网站与博客。从wordpress博客添加“Recent Posts”到html静态页面
但我是一个可怕的PHP程序员..所以我创建了HTML/CSS和WordPress的博客整个网站。 好吧,听起来不错!但如何把博客(wordpress)的“最近的帖子”放在我的索引html页面中?
答
方法1:wp_get_recent_posts()
据WordPress的抄本:wp_get_recent_posts()将返回帖子列表。与返回post对象数组的get_posts不同。
<?php
include('blog/wp-load.php'); // Blog path
// Get the last 5 posts
$recent_posts = wp_get_recent_posts(array(
'numberposts' => 5,
'post_type' => 'post',
'post_status' => 'publish'
));
// Display them as list
echo '<ul>';
foreach($recent_posts as $post) {
echo '<li><a href="', get_permalink($post['ID']), '">', $post['post_title'], '</a></li>';
}
echo '</ul>';
?>
方法2:WordPress的循环
<?php
define('WP_USE_THEMES', false);
include('blog/wp-load.php'); // Your blog path
//Get 5 posts
query_posts('showposts=5');
// Display them as list
echo '<ul>';
foreach($recent_posts as $post) {
echo '<li><a href="', the_permalink(), '">', the_title(), '</a></li>';
}
echo '</ul>';
?>
它的工作!谢谢,我的朋友! –
如何在我的html页面添加? –