How To Integrate WordPress Latest Blog Post Into PHP Website

How To Integrate Wordpress Blog Into Website

If you want to display latest wordpress blog on your homepage follow the instructions below:

Before you use code, confirm your page is saved with the .php extension and your WordPress installation is in a sub-directory on you domain like www.websolindia.com/blog/

How To Integrate WordPress Latest Blog Into Php Website

How To Integrate WordPress Latest Blog Into Php Website
How To Integrate WordPress Latest Blog Into Php Website

Most important to understand you need access to wp-load.php

Copy and paste code:

<ul>
<?php
require($_SERVER['DOCUMENT_ROOT'] . '/wordpress/wp-load.php');
$args = array(
// 'cat' => 3, // 
'posts_per_page' => 2 // 
);
$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 if ( has_post_thumbnail() ) { ?>
<span class="post_thumbnail"><?php the_post_thumbnail(); ?></span>
<?php } ?>
<span class="post_title"><?php the_title(); ?></span>
</a>
<span class="post_time">Posted on <?php the_time('l jS F, Y') ?></span>
<?php the_excerpt(); ?>
</li>
<? }
} else {
echo '<p>There are no posts available</p>';
}
wp_reset_postdata();
?>
</ul>

For more information on integrate wordpress latest blog into php website home page contact Websolindia on of the leading Website Development Agency in India.

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *