Created
January 6, 2017 12:44
-
-
Save Antoinebr/bcddf18946ad8c54de587510bee8c23b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html class="no-js"> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<title></title> | |
<meta name="description" content=""> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
</head> | |
<body> | |
<?php | |
error_reporting(E_ALL); | |
ini_set('display_errors', 1); | |
// Lib used https://github.com/cosenary/Simple-PHP-Cache | |
require_once 'libs/cache.class.php'; | |
$c = new Cache(); | |
$c->eraseExpired(); | |
if($c->isCached("posts") === false){ | |
echo " \n <!-- \n \n \n posts are NOT cached \n \n \n--> \n"; | |
// Get the content | |
$rest = file_get_contents('https://monbraceletnato.fr/wp-json/wp/v2/posts'); | |
// Transform the JSON to an php array | |
$rest = json_decode($rest); | |
// cache the array for 24H (60s * 60min * 24h) | |
$c->store('posts', $rest,60*60*24 ); | |
}else{ | |
echo " \n <!-- \n \n \n posts are cached \n \n \n--> \n"; | |
// Get posts from cache | |
$posts = $c->retrieve('posts'); | |
// loop the posts | |
foreach ($posts as $post) { | |
echo $post->content->rendered; | |
} | |
} | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment