there are some sites where the installation of wordpress is in a subfolder called news and I need to display a list of posts in the index, searching the internet I saw that wordpress generated a JSON of the posts. So by giving one more lookup I get to display, however the method I'm using is via PHP's " file_get_contents ", there every time I have to log in to CPANEL and enable an option there, due to issues of security.
That's when a guy I had contact told me to use CURL , here comes the question, how do I get the pots and featured image?
Below I'm going for the code I'm currently using 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>';
}
?>