简体   繁体   English

将来自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 . 我正在开发一个新项目,我的客户需要一个带有Blog网站

But I'm a terrible PHP programmer.. So I created the entire site on HTML/CSS and the blog with wordpress. 但是我是一个糟糕的PHP程序员。.所以我在HTML / CSS和wordpress博客上创建了整个网站。 OK, sounds good! 好的听起来不错! but how to put the "Recent posts" from the blog(wordpress) in my index html page? 但是如何将博客(wordpress)中的“最新帖子”放在我的索引html页面中?

Method 1 : wp_get_recent_posts() 方法1:wp_get_recent_posts()

According to WordPress codex: wp_get_recent_posts() will return a list of posts. 根据WordPress规范:wp_get_recent_posts()将返回帖子列表。 Different from get_posts which returns an array of post objects. 与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>';

?>

Method 2 : WordPress loop 方法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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM