Created
January 8, 2014 11:49
-
-
Save amyinorbit/8315723 to your computer and use it in GitHub Desktop.
Sample (probably not right) json index generation code for wordpress
This file contains hidden or 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
<?php | |
$postsArray = Array(); // un tableau vide | |
while ( have_posts() ) : the_post(); // on boucle avec tous les articles | |
$currentPost = Array(); // un tableau vide pour l'article en cours | |
$currentPost["title"] = the_title(); // on ajoute le titre | |
$currentPost["url"] = the_permalink(); // l'url | |
array_push($postsArray, $currentPost); // et on ajoute le tableau de l'article au tableau global | |
endwhile; | |
$json = json_encode($postsArray); // on encode tout ça en JSON | |
if(file_put_contents($json, "/chemin/vers/le/fichier/json.json")) { // on ecrit tout ca dans un fichier | |
throw new Exception("Probleme lors de l'ecrtiture du fichier"); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment