This question already has an answer here:
-
Include Wordpress Core into own Scripts
3 answers
Is it possible to load only some contents outside the wordpress installation directory? I'm working on a website and I want to embed some blog contents on a static index.php
made using bootstrap4. This page is not part of the wordpress installation, so I want to understand if this is possible and how.
Try this:
Note: change the 'path-to-wordpress' to actual wp directory path.
define('WP_USE_THEMES', FALSE);
require('/path-to-wordpress/wp-load.php');
$args = array(
'posts_per_page' => 5 // 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(); ?>
<li>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
<?php the_excerpt(); ?>
</li>
<?php }
}
else {
echo '<p>There are no posts</p>';
}
wp_reset_postdata();
wp_reset_query();