Метод 1: wp_get_recent_posts()
Согласно WordPress Codex: wp_get_recent_posts() возвращает список сообщений. В отличие от 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? –