/
home
/
faureele
/
extra-til
/
wp-content
/
themes
/
woffice-child-theme
/
api-til
/
Upload File
HOME
<?php // Affiche un article du site just-carsregion.fr "Covid19" require_once 'HTTP/Request2.php'; $request = new HTTP_Request2(); $request->setUrl('https://www.just-carsregion.fr/wp-json/wp/v2/media/1174'); $request->setMethod(HTTP_Request2::METHOD_GET); $request->setConfig(array( 'follow_redirects' => TRUE )); $request->setHeader(array( 'Cookie' => 'Cookie_1=value; PHPSESSID=b0abd763867762d743ccd4da192171aa' )); try { $response = $request->send(); if ($response->getStatus() == 200) { $results=$response->getBody(); $resultDecode=json_decode($results, true); $nbArticles=count($resultDecode); // echo "Il y a actuellement ".$nbArticles." article(s) dans la partie <b>blog</b> de publié(s) sur <a href='https://www.just-carsregion.fr' target='_blank'>Just TIL</a><br>"; // image = wp:featuredmedia > href https://www.just-carsregion.fr/wp-json/wp/v2/media/1174 (novuelle page) > guid > rendered foreach($resultDecode as $article){ echo " <div class='container-sm'> <img src='' class='' alt='image".$article['slug']."' /> <div style='padding:20px'> <h4>".$article['title']['rendered']."</h4> <span>Publié le : ".$article['modified_gmt']."</span> <p>".$article['excerpt']['rendered']."</p> <a href='".$article['link']."' class='btn btn-primary' target='_blank'>Voir l'article</a> </div> </div>"; } // $resultDecode=array(); }else { echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' . $response->getReasonPhrase(); } } catch(HTTP_Request2_Exception $e) { echo 'Error: ' . $e->getMessage(); }