NUKnightLab / TimelineJS-Wordpress-Plugin

A simple shortcode plugin to add the Timeline to Wordpress
Other
207 stars 50 forks source link

Display posts feature #10

Open miguelpeixe opened 12 years ago

miguelpeixe commented 12 years ago

Support posts to be displayed on the Timeline using JSON API wp plugin.

Use/improve this code for start: http://pastebin.com/SwbT2J9A

kukrapoke commented 12 years ago

Hi miguel ! Thank you very much for your great controller. However, I have a problem with dates of posts that seem doesn't work correctly, i don't know why. Here is my code : <?php echo do_shortcode('[timeline src="http://jm-mosse.com/api/timeline/category_posts/?category_id=null&post_type=post&amount=-1&main_post_id=1"]'); ?> Can you help me please ? Thanks !

miguelpeixe commented 12 years ago

Hi kukrapoke, it looks ok, but all the events are on the same day. If you want to use custom dates (other than post publish date) I recommend using a custom meta to fill this data.

Could be something like this:

 $json['timeline']['date'][$i]['startDate'] = date('Y,m,d', strtotime(get_post_meta($main_post->ID, 'start_date', TRUE));
kukrapoke commented 12 years ago

Hi miguel, i showed your code to a friend who found an error, now everything is working properly. The error is line 68 and 69 : $json['timeline']['date'][$i]['startDate'] = date('Y,m,d', strtotime($main_post->post_date)); $json['timeline']['date'][$i]['endDate'] = date('Y,m,d', strtotime($main_post->post_date));

You need to replace $main_post by $post. Thanks again for your controller.

miguelpeixe commented 12 years ago

Fixed it, thank you!

aaronsmulktis commented 12 years ago

hey all!

got the JSON API plugin installed, and configured correctly, got the Verite plugin installed. Tried putting your pastebin code in my functions.php file, and adjusted the source URL for the plugin, doesn't work.

Where I put this controller script?

You guys are the best, this stuff is so good.

aaronsmulktis commented 12 years ago

sorry URL to project is here: http://beringerguitars.org/

Also, I've now tried dropping the script into the core.php file in the JSON plugin folder, even tried creating a timeline.php file and dropping in there. Still not working.

Would love a little help. Thanks!!!

kukrapoke commented 12 years ago

Hi aaronsmulktis !

First you have to put the pastebin code into a file like timeline.php and save this file into /plugins/json-api/controllers/

After you need to activate this controller in the JSON API Settings in WP admin.

To complete you have to paste your JSON API shorcode anywhere in your template like this : <?php echo do_shortcode('[timeline src="http://beringerguitars.org/api/timeline/category_posts/?category_id=null&post_type=post&amount=-1&main_post_id=1"]'); ?>

Voila ! Thanks again to Miguel !

aaronsmulktis commented 12 years ago

Thanks so much for the quick help Miguel!

When I inspect the element, the timeline-embed div is there, and I've deleted and reinstalled the plugin, but even when I specify the width/height in the short code (or php) nothing displays..

weeiirrddd

aaronsmulktis commented 12 years ago

also when I test the JSON API by clicking on my timeline controller "category_posts" link, it returns the correct data. so that should be working fine. just don't know why it isn't loading that data into the timeline.

aaronsmulktis commented 12 years ago

sorry thank YOU kukrapoke for the speedy help! :P

ghost commented 12 years ago

Hey. Thanks for the awesome plugin. I was wondering how to add a photo credit to the json controller.

I tried this:

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];
            $json['timeline']['asset']['credit'] = get_post_meta($main_post->ID, 'user_submit_name');
        }

But it doesnt work. The source outputs

"asset":{"media":"URLToMedia","credit":["John Doe"]}

why is it adding surrounding it with []?

miguelpeixe commented 12 years ago

Hi LSDLTD,

As you can see on get_post_meta function reference you should use get_post_meta($main_post->ID, 'user_submit_name', TRUE); to output a single value instead of an array. The third argument is set to false by default, to get an array of post metas.

ghost commented 12 years ago

Ah! Thank you!