添加“最近的帖子"从 wordpress 博客到 html 静态页面 [英] Add "Recent Posts" from a wordpress blog to a html static page
问题描述
我正在做一个新项目,我的客户需要一个带有博客的网站.
I'm working on a new project and my client needs a site with blog.
但我是一个糟糕的 PHP 程序员.. 所以我用 HTML/CSS 创建了整个网站,并用 wordpress 创建了博客.好的听起来不错!但是如何将博客(wordpress)中的最近的帖子"放在我的索引 html 页面中?
But I'm a terrible PHP programmer.. So I created the entire site on HTML/CSS and the blog with wordpress. OK, sounds good! but how to put the "Recent posts" from the blog(wordpress) in my index html page?
推荐答案
方法一:wp_get_recent_posts()
根据 WordPress 代码: wp_get_recent_posts() 将返回一个帖子列表.与 get_posts 不同,它返回一个 post 对象数组.
According to WordPress codex: wp_get_recent_posts() will return a list of posts. Different from get_posts which returns an array of post objects.
<?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>';
?>
方法二: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>';
?>
这篇关于添加“最近的帖子"从 wordpress 博客到 html 静态页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!