I am trying to figure out how to get the 3 latest WordPress posts and display each in its own div on a static HTML page, outside of WordPress. The PHP I am using will pull any number of posts, however, they all display in the same div. In the screen capture, I just replicated the PHP 3 times, each in a new div. I would like to display a different post in each div.
PHP I am using
<?php
require($_SERVER['DOCUMENT_ROOT'] . '/blog/wp-load.php');
$args = array(
// 'cat' => 3, // Only source posts from a specific category
'posts_per_page' => 1 // Specify how many posts you'd like to display
);
$latest_posts = new WP_Query( $args );
if ( $latest_posts->have_posts() ) {
while ( $latest_posts->have_posts() ) {
$latest_posts->the_post(); ?>
/wp-json/wp/v2/posts
, and it would be more reliable too