Skip to main content
added 11 characters in body
Source Link
Tom J Nowell
  • 60.6k
  • 7
  • 77
  • 147

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(); ?>

            <?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(); ?>

static html page displaying wordpress posts

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(); ?>

static html page displaying wordpress posts

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(); ?>

static html page displaying wordpress posts

Source Link

Display the 3 latest WordPress Posts on a Static Page Outside WordPress

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(); ?>

static html page displaying wordpress posts