Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Controller name: timeline
- Controller description: Data manipulation methods for timeline posts in the verite format
- */
- class JSON_API_Timeline_Controller {
- public function timeline_posts() {
- global $json_api;
- $json = array();
- $main_post_id = $json_api->query->main_post_id;
- $post_type = 'post';
- $amount = -1;
- $posts = get_posts(array('post_type' => $post_type, 'numberposts' => $amount, 'orderby' => 'post_date', 'order' => 'DESC'));
- $main_post = get_post($main_post_id);
- if($main_post) {
- // setting first (main) post
- $json['timeline'] = array();
- $json['timeline']['headline'] = $main_post->post_title;
- $startDate=get_post_meta($post->ID, 'startDate',true); //gets the startdate from the custom fields plugin
- $json['timeline']['date'][$i]['startDate'] = $startDate;
- $json['timeline']['type'] = 'default';
- $json['timeline']['text'] = $main_post->post_content;
- /*
- if(has_post_thumbnail($main_post->ID)) {
- $thumbnail_id = get_post_thumbnail_id($main_post->ID);
- $thumbnail_src = wp_get_attachment_image_src($thumbnail_id, 'medium');
- $json['timeline']['asset']['media'] = $thumbnail_src[0];
- }
- */
- if($posts) {
- $json['timeline']['date'] = array();
- $i = 0;
- foreach($posts as $post) {
- $startDate=get_post_meta($post->ID, 'startDate',true); //gets the enddate from the custom fields plugin
- $endDate=get_post_meta($post->ID, 'endDate',true); //gets the enddate from the custom fields plugin
- $json['timeline']['date'][$i]['startDate'] = $startDate;
- $json['timeline']['date'][$i]['endDate'] = $endDate;
- $json['timeline']['date'][$i]['headline'] = $post->post_title;
- $json['timeline']['date'][$i]['text'] = $post->post_content;
- //preg_replace( $json['timeline']['date'][$i]['text'] ,'class="','class="lightbox ')
- // example of media asset using the post thumbnail
- /* if(has_post_thumbnail($post->ID)) {
- $thumbnail_id = get_post_thumbnail_id($post->ID);
- $thumbnail_src = wp_get_attachment_image_src($thumbnail_id, 'medium');
- $json['timeline']['date'][$i]['asset']['media'] = $thumbnail_src[0];
- }
- */
- $i++;
- }
- return $json;
- } else return 'Posts not found';
- } else return 'Main post not found';
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement