Skip to content

Instantly share code, notes, and snippets.

@amyinorbit
Created January 8, 2014 11:49
Show Gist options
  • Save amyinorbit/8315723 to your computer and use it in GitHub Desktop.
Save amyinorbit/8315723 to your computer and use it in GitHub Desktop.
Sample (probably not right) json index generation code for wordpress
<?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