Make a json page for Ajax
-
Hi erveryone,
Recently I tried to make a page with some info about my posts encoded in JSON. So, I create a page template with this code:
<?php
/*
Template Name: Ajax loader
*/
header("Content-Type: text/json");
?>
[<?php
global $post;
$myposts = get_posts();
foreach($myposts as $post){
$id = get_the_ID();
$title = get_the_title();
$content = get_the_content();?>{"title":<?php echo json_encode($title); ?>,"content":<?php echo json_encode($content); ?>,"id":<?php echo $id; ?>},<?php
}
?>{"end":true}]The title appear, but not the content and the ID..
Could someone help me ? Please ?
Thank you.
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Make a json page for Ajax’ is closed to new replies.