[英]Add “Recent Posts” from a wordpress blog to a html static page
我正在开发一个新项目,我的客户需要一个带有Blog的网站 。
但是我是一个糟糕的PHP程序员。.所以我在HTML / CSS和wordpress博客上创建了整个网站。 好的听起来不错! 但是如何将博客(wordpress)中的“最新帖子”放在我的索引html页面中?
方法1:wp_get_recent_posts()
根据WordPress规范:wp_get_recent_posts()将返回帖子列表。 与get_posts不同,后者返回一个post对象数组。
<?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>';
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.