0
has some sites where the wordpress installation is in a subfolder called news and need to display a list of posts on the index, searching the internet saw that wordpress generated a JSON of the posts. So giving one more sweep manage to display, however the method I’m using is via "file_get_contents" PHP, there every time I have to enter the CPANEL and enable an option there, due to security issues.
That’s when a guy I had contact with said I should use CURL, Here comes the question, how do I get the pots and highlight image?
Below I will put the code I am using at the moment that is not recommended.
<?php
$posts = file_get_contents('http://www.hospitalpadreze.org.br/noticias/wp-json/wp/v2/posts?per_page=2');
$obj = json_decode($posts);
foreach ($obj as $post) {
$id = ($post->id);
echo '<div class="box">';
$thumbnail = file_get_contents('http://www.hospitalpadreze.org.br/noticias/wp-json/wp/v2/media?parent=' . $id . '');
$images = json_decode($thumbnail);
foreach ($images as $image) {
echo '<div class="imagem-destaque">';
echo '<a href="' . $post->link . '">';
echo '<img src="' . $image->media_details->sizes->index_blog->source_url . '"/>';
echo '</a>';
echo '</div>';
}
echo '<h2><a href="' . $post->link . '">' . $post->title->rendered . '</a></h2>';
echo '</div>';
}
?>