Introduction:
WordPress is the world’s most popular content management system, powering over 40% of all websites on the internet. One of the many benefits of using WordPress is its flexibility and ease of use, allowing users to customize their websites to their specific needs.
However, when it comes to displaying WordPress blog posts outside of the WordPress installation directory, things can get a bit tricky. By default, WordPress loads all of its content within the WordPress directory, but with a few modifications to your site’s code, you can display your blog posts anywhere on your website.
In this article, we’ll walk you through the steps to load WordPress blog posts outside of the WordPress installation directory.
To do this, follow these steps:
Open the page where you want to display your blog posts.
and paste these codes and save it.
<?php require($_SERVER['DOCUMENT_ROOT'] . '/blog/wp-load.php');
$recent_blog = array(
'post_type'=> 'post',
'numberposts' => 3,
'post_status' => 'publish',
'order' => 'DESC'
);
$latest_blog = get_posts( $recent_blog );
?>
<div class="rel-blogs">
<div class="container">
<h2 class="rel-blogs-headline-sec">Related Blogs</h2>
<div class="decoration">
<div class="decoration-inside"></div>
</div>
<div class="row">
<?php
foreach ($latest_blog as $latestblog) {
?>
<div class="col-sm-4">
<a class="rpwe-img" href="<?php echo get_permalink( $latestblog->ID ); ?>" rel="bookmark">
<img class="rpwe-aligncenter rpwe-thumb" src=" echo get_the_post_thumbnail_url($latestblog->ID, 'medium'); ?>" alt=" <?php echo $latestblog->post_title ?>"></a>
<div class="rpwe-content">
<h3 class="rpwe-title"><a href="<?php echo get_permalink( $latestblog->ID ); ?>" title=" <?php echo $latestblog->post_title ?>" rel="bookmark"> <?php echo $latestblog->post_title ?> </a></h3>
<div class="rpwe-summary">
<p> <?php echo wp_trim_words($latestblog->post_content, 37, '' ); ?></p>
</div>
</div>
<div class="rpwe-btn">
<a href="<?php echo get_permalink( $latestblog->ID ); ?>" class="more-link">Read More ยป</a>
</div>
</div>
<?php }
?>
</div>
</div>
</div>
<!------------- End of blogs ----------------->
After modifying your site’s code, it’s essential to test your website to ensure that everything is working correctly. Here are a few things to check:
* Are your blog posts being loaded outside of the WordPress installation directory?
* Do your blog posts appear correctly on the page.
I hope you enjoyed this article. If you liked it please share with needy.