Search code examples
phphtmlcsswordpressblogs

Integrate Wordpress recent posts into existing website


I already have a static website and I want to integrate wordpress site (blog) into existing one. Just to point out that I am Wordpress rookie, so I'm still finding my way to understand the way wordpress works.

Here is what I'm trying to achieve:

I want to show recent posts on my index.php page, while wordpress site is sitting in sub directory.

I've followed this guide: https://codex.wordpress.org/Integrating_WordPress_with_Your_Website

And added following code to the start of index.php

<?php
// Include Wordpress
define('WP_USE_THEMES', false);
require('wordpress/wordpress/wp-blog-header.php');
?>

Now in body section of my index.php i want to show recent posts from wordpress site, so I added following:

<?php
$posts = get_posts('numberposts=10&order=ASC&orderby=post_title');
foreach ($posts as $post) : setup_postdata( $post ); ?>
<?php the_date(); echo "<br />"; ?>
<?php the_title(); ?>    
<?php the_excerpt(); ?> 
<?php
endforeach;
?>

Now I managed to output raw text to my index.php, without any styling beeing applied to it and images are missing from my posts, even though i linked properly style.css file from wordpress default theme.

How to get default wordpress theme styling to be applied to those recent posts? and of course to get those images from posts to show up as well?

I also watched this tutorial where he managed to achieve my goal, but it's not explained exactly how.

https://www.youtube.com/watch?v=TUWu3J359AY&t=559s

Also not sure, since it is old video, maybe something changed in newer versions of Wordpress.

I've lost so much time on this and I'm hoping that someone could help me out, or at least to point me out to the right direction.

I apologize in advance if this is duplicate post, however I was unable to find one.

Thanks in advance.


Solution

  • Use Ajax call to do this or the short way, use the iframe and style a little. things will be ready to use immediately.