1

I've had a VeriteCO Timeline dynamicaly populated by that was working since 2012.
It doesn't work anymore.
I had To update to KhniteLab TimelineJS Plugin.
I used a custom Timeline controller :

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';

    }

} 

But my [tag:Json url] which worked fine before doesn't anymore. I've seen on https://timeline.knightlab.com/docs/json-format.html that now there's a need for an events list of slides though I've changed my loop controller part to :

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;

I can't seem to get it right.
The output should look like this example on KhniteLab site :

{
    "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."
        }
      },

and it looks like that in my case :

  <!-- <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":

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

I use to call the Timeline in my front-page.php as this :

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']"); 

How could I do now?
I'm trying lots of solutions for more than 10 days and can't seem to find the solution. Only that the problem comes from my controller which doesn't fit the new needs.
My timeline page : [http://conexion.cluster003.ovh.net/blog/][3]

Jane Seneor
  • 11
  • 1
  • 5

0 Answers0