如何更新Json控制器以动态填充新的TimelineJS插件

时间:2018-02-15 19:15:54

标签: javascript php json controller timeline.js

我有动态填充的VeriteCO时间表,自2012年开始运作。
它不再起作用了。
我必须更新到KhniteLab TimelineJS插件 我使用了自定义时间轴控制器:

class JSON_API_Timeline_Controller {

    public function category_posts() {
        global $json_api;
        $json = array();

        // get attributes
        $category_id = $json_api->query->category_id;
        $post_type = $json_api->query->post_type;
        $amount = $json_api->query->amount;
        $main_post_id = $json_api->query->main_post_id;

        if(!$post_type) $post_type = 'post';
        if(!$amount) $amount = -1;

        $posts = get_posts(array('post_type' => $post_type, 'numberposts' => $amount, 'category' => $category_id, 'orderby' => $eventdate, 'order' => 'DESC'));

        if($main_post_id) $main_post = get_post($main_post_id);
        else  {
            $main_post = $posts[0];
            unset($posts[0]);
        }

        if($main_post) {

            // setting first (main) post

            $json['timeline'] = array();

            $json['timeline']['headline'] = $main_post->post_title;
            $json['timeline']['type'] = 'default';
            $json['timeline']['startDate'] = date('Y,m,d', strtotime($main_post->post_date));
            $json['timeline']['text'] = $main_post->post_excerpt;

            // example of media asset using the post thumbnail
            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, 'large');
                $json['timeline']['asset']['media'] = $thumbnail_src[0];

            }

            if($posts) {
                $json['timeline']['date'] = array();
                $i = 0;
                foreach($posts as $post) {

                    $json['timeline']['date'][$i]['startDate'] = date_i18n('Y,m,d', strtotime(get_post_meta($post->ID, "_datepicker", true)));
                    $json['timeline']['date'][$i]['endDate'] = date_i18n('Y,m,d', strtotime(get_post_meta($post->ID, "_datepicker", true)));
                    if ( has_post_format( 'aside',$post->ID ) ) {
                    $json['timeline']['date'][$i]['headline'] = $post->post_title;
                    $json['timeline']['date'][$i]['text'] = '<span class="timelinelieu">'.get_post_meta($post->ID, "event_lieu", true).'</span>'.$post->post_content;
                    } else {
                    $json['timeline']['date'][$i]['headline'] = '<a href="'.get_permalink($post->ID).'">'.$post->post_title.'</a>';
                    $typelist = '';
                    if ($eventtypes = get_field("type_de_event", $post->ID)) {
                        if(is_array($eventtypes)) {
                            foreach ($eventtypes as $key => $eventtype) {
                                $typelist .= $eventtype . ' | ';
                            }
                        $typelist = substr($typelist, 0, -2);
                        $typelist = '<br><span class="timelinetype">'.$typelist.'</span>';
                        } 
                    }
                    $json['timeline']['date'][$i]['text'] = '<span class="timelinelieu">'.get_post_meta($post->ID, "event_lieu", true).'</span>'.$post->post_excerpt.$typelist;

                    // 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, 'large');

                        $json['timeline']['date'][$i]['asset']['media'] = $thumbnail_src[0];}
                    }

                    $i++;

                }

                return $json;

            } else return 'Posts not found';

        } else return 'Main post not found';

    }

} 

但我的[标签:Json url]以前工作得很好,不再了。 我已经在https://timeline.knightlab.com/docs/json-format.html看到现在需要一个幻灯片的事件列表,虽然我已经将我的循环控制器部分更改为:

if($main_post) {

    // setting first (main) post

    $json['timeline'] = array();

    $json['timeline']['headline'] = $main_post->post_title;
    $json['timeline']['type'] = 'default';
    $json['timeline']['startDate'] = date('Y,m,d', strtotime($main_post->post_date));
    $json['timeline']['text'] = $main_post->post_excerpt;

    $json['timeline']['events'] = array();

    // example of media asset using the post thumbnail
    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, 'large');
        $json['timeline']['events']['media'] = $thumbnail_src[0];

    }

    if($posts) {
        //$json['timeline']['events']['date'] = array();
        $json['timeline']['events'][$i]['text'] = array();
        $i = 0;
        foreach($posts as $post) {

            $json['timeline']['events'][$i]['startDate'] = date_i18n('Y,m,d', strtotime(get_post_meta($post->ID, "_datepicker", true)));
            $json['timeline']['events'][$i]['endDate'] = date_i18n('Y,m,d', strtotime(get_post_meta($post->ID, "_datepicker", true)));
            if ( has_post_format( 'aside',$post->ID ) ) {
            $json['timeline']['events'][$i]['text']['headline'] = $post->post_title;
            $json['timeline']['events'][$i]['text']['text'] = '<span class="timelinelieu">'.get_post_meta($post->ID, "event_lieu", true).'</span>'.$post->post_content;
            } else {
            $json['timeline']['events'][$i]['text']['headline'] = '<a href="'.get_permalink($post->ID).'">'.$post->post_title.'</a>';
            $typelist = '';
            if ($eventtypes = get_field("type_de_event", $post->ID)) {
                if(is_array($eventtypes)) {
                    foreach ($eventtypes as $key => $eventtype) {
                        $typelist .= $eventtype . ' | ';
                    }
                $typelist = substr($typelist, 0, -2);
                $typelist = '<br><span class="timelinetype">'.$typelist.'</span>';
                } 
            }
            $json['timeline']['events'][$i]['text']['text'] = '<span class="timelinelieu">'.get_post_meta($post->ID, "event_lieu", true).'</span>'.$post->post_excerpt.$typelist;

            // 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, 'large');

                $json['timeline']['events'][$i]['media']['url'] = $thumbnail_src[0];}
            }

            $i++;

        }

        return $json;

我似乎无法做到这一点 输出应该在KhniteLab站点上看起来像这个例子:

{
    "title": {
        "media": {
          "url": "//www.flickr.com/photos/tm_10001/2310475988/",
          "caption": "Whitney Houston performing on her My Love is Your Love Tour in Hamburg.",
          "credit": "flickr/<a href='http://www.flickr.com/photos/tm_10001/'>tm_10001</a>"
        },
        "text": {
          "headline": "Whitney Houston<br/> 1963 - 2012",
          "text": "<p>Houston's voice caught the imagination of the world propelling her to superstardom at an early age becoming one of the most awarded performers of our time. This is a look into the amazing heights she achieved and her personal struggles with substance abuse and a tumultuous marriage.</p>"
        }
    },
    "events": [
      {
        "media": {
          "url": "{{ static_url }}/img/examples/houston/family.jpg",
          "caption": "Houston's mother and Gospel singer, Cissy Houston (left) and cousin Dionne Warwick.",
          "credit": "Cissy Houston photo:<a href='http://www.flickr.com/photos/11447043@N00/418180903/'>Tom Marcello</a><br/><a href='http://commons.wikimedia.org/wiki/File%3ADionne_Warwick_television_special_1969.JPG'>Dionne Warwick: CBS Television via Wikimedia Commons</a>"
        },
        "start_date": {
          "month": "8",
          "day": "9",
          "year": "1963"
        },
        "text": {
          "headline": "A Musical Heritage",
          "text": "<p>Born in New Jersey on August 9th, 1963, Houston grew up surrounded by the music business. Her mother is gospel singer Cissy Houston and her cousins are Dee Dee and Dionne Warwick.</p>"
        }
      },
      {
        "media": {
          "url": "https://youtu.be/fSrO91XO1Ck",
          "caption": "",
          "credit": "<a href=\"http://unidiscmusic.com\">Unidisc Music</a>"
        },
        "start_date": {
          "year": "1978"
        },
        "text": {
          "headline": "First Recording",
          "text": "At the age of 15 Houston was featured on Michael Zager's song, Life's a Party."
        }
      },

看起来像我的情况:

  <!-- <script> -->
<!-- 
//  jQuery(document).ready(function(){
//  jQuery("#page").fitVids();
//  });
 -->
 <!-- </script> -->
 {"status":"ok","timeline":{"headline":"Cie Les Gens De...","type":"default","startDate":"2017,11,17","text":"En ayant la volont\u00e9 de pr\u00e9senter une danse ouverte sur d\u2019autres modes d\u2019expression, La compagnie recherche ainsi l\u2019essence de l\u2019art sc\u00e9nique et s\u2019accomplie dans la po\u00e9sie.","events":{"":{"text":[]},"0":{"startDate":"2018,02,15","endDate":"2018,02,15","text":{"headline":"<a href=\"http:\/\/conexion.cluster003.ovh.net\/blog\/blog\/news\/news_spectacles\/gerard-diby\/\">G\u00e9rard Diby<\/a>","text":"<span class=\"timelinelieu\">Bures sur Yvette (91)<\/span>Danseur soliste des Ballets Nationaux de C\u00f4te d'Ivoire,Cie Wazy,Cie la Calebasse, Cie G. Momboye...<br><span class=\"timelinetype\">CO2NEXIONS <\/span>"},"media":{"url":"http:\/\/conexion.cluster003.ovh.net\/blog\/wp-content\/uploads\/medias\/2017\/11\/gerard.jpg"}},"1":{"startDate":"2018,02,15","endDate":"2018,02,15","text":{"headline":"<a href=\"http:\/\/conexion.cluster003.ovh.net\/blog\/blog\/activites\/hiphop\/ludovic-ilolo-aka-ucka-delia\/\">Ludovic Ilolo aka Ucka D\u00e9lia<\/a>","text":"<span class=\"timelinelieu\">Bures sur Yvette (91)<\/span>Com\u00e9dien, Danseur, Chanteur, Chor\u00e9graphe, R\u00e9petiteur... Cie Les Gens De...<br><span class=\"timelinetype\">CO2NEXIONS <\/span>"},"media":{"url":"http:\/\/conexion.cluster003.ovh.net\/blog\/wp-content\/uploads\/medias\/2017\/11\/image003.jpg"}},"2":{"startDate":"2018,02,15","endDate":"2018,02,15","text":{"headline":"<a href=\"http:\/\/conexion.cluster003.ovh.net\/blog\/blog\/news\/thierno-thioune\/\">Thierno Thioune<\/a>","text":"<span class=\"timelinelieu\">Bures sur Yvette (91)<\/span>Eleve CO2NEXIONS depuis 2000. Cie Gecko et projet \"Kor\u00e9grafs\". Intervenant CO2NEXIONS depuis 2004.<br><span class=\"timelinetype\">CO2NEXIONS <\/span>"},"media":{"url":"http:\/\/conexion.cluster003.ovh.net\/blog\/wp-content\/uploads\/medias\/2017\/11\/thiernolukas2.jpg"}},"3":{"startDate":"2018,02,15","endDate":"2018,02,15","text":{"headline":"<a href=\"http:\/\/conexion.cluster003.ovh.net\/blog\/blog\/news\/news_infos\/des-nouveaux-sites-web-co2nexions-en-flash\/\"> Des nouveaux sites Web CO2NEXIONS en flash!<\/a>","text":"<span class=\"timelinelieu\">Bures sur Yvette (91)<\/span><br><span class=\"timelinetype\">CO2NEXIONS <\/span>"},"media":{"url":"http:\/\/conexion.cluster003.ovh.net\/blog\/wp-content\/uploads\/medias\/2017\/11\/Capture-d\u2019e\u0301cran-26.png"}},"4":

http://conexion.cluster003.ovh.net/blog/api/timeline/category_posts/?category_id=4

我用我的 front-page.php调用时间轴,如下所示:

echo do_shortcode("[timeline src='http://conexion.cluster003.ovh.net/blog/api/timeline/category_posts/?category_id=4&hash_bookmark=true&start_zoom_adjust=3&main_post_id=1136']"); 

我现在该怎么办? 我尝试了很多解决方案超过10天,似乎无法找到解决方案。只是问题来自我的控制器,它不适合新的需求 我的时间线页面:[http://conexion.cluster003.ovh.net/blog/][3]

0 个答案:

没有答案