json格式post到wordpress

<?php// include our wordpress functions// change relative path to find your WP dirdefine('WP_USE_THEMES',false);require('./wp-blog-header.php');// set header for json mime typeheader('Content-type: application/json;');// get latest single post// exclude a category (#5)query_posts(array('posts_per_page'=>5,'cat'=>-5,));$jsonpost = array();if(have_posts()){if( have_posts()):while( have_posts()): the_post();// construct our array for json// apply_filters to content to process shortcodes, etc        $jsonpost["id"]= get_the_ID();        $jsonpost["title"]= get_the_title();        $jsonpost["url"]= apply_filters('the_permalink', get_permalink());// $jsonpost["content"] = apply_filters('the_content', get_the_content());        $images = get_children( array('post_parent'=> $post->ID,'post_type'=>'attachment','post_mime_type'=>'image','orderby'=>'menu_order','order'=>'ASC','numberposts'=>999));if( $images ){        $total_images = count( $images );            $image = array_shift( $images );            $jsonpost['featured_image']= wp_get_attachment_image( $image->ID,'thumbnail');}        $jsonpost["content"]= get_the_content();// would rather do iso 8601, but not supported in gwt (yet)        $jsonpost["date"]= get_the_time('d F Y');        $jsonposts[]= $jsonpost;     endwhile;    endif;}else{// deal with no posts returned}// output json to fileheader('Cache-Control: no-cache, must-revalidate');header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');header('Content-type: application/json');echo json_encode($jsonposts);

人吐槽 人点赞

猜你喜欢

发表评论

用户名: 密码:
验证码: 匿名发表

你可以使用这些语言

查看评论:json格式post到wordpress