View wordpress posts with SQL

0

I'm doing a static site, where all the files are in PHP, however this site has a blog that must be managed by Wordpress, there you ask me and why not do everything by Wordpress? because it is rsrsr order are orders né.

Then I had the idea of creating a folder called "noticias" where I will install Wordpress, then it will be domain / news.

Only I need to display the last two news on the home page, ie outside of Wordpress, I know I'll have to create a file to connect to the database and do the include in index.php and write a sentence in SQL, but I'm very lazy about it, could you give me a light?

    
asked by anonymous 17.07.2017 / 22:05

1 answer

2
  

I know I'll have to create a file to connect to the database.   data and make the include in index.php and write a sentence in SQL

You do not need any of this. As of version 4.7 you can use the REST API from WordPress to pull the data. The only requirement is that you are using pretty-permalinks (anything other than seusite.com?p=342 for example).

$posts = file_get_contents( 'http://seuwordpress.com/wp-json/wp/v2/posts' );

$posts is now a JSON object containing the latest site posts. Equivalent to what the homepage would look like.

    
18.07.2017 / 14:21