Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display posts feature #10

Open
miguelpeixe opened this issue May 1, 2012 · 13 comments
Open

Display posts feature #10

miguelpeixe opened this issue May 1, 2012 · 13 comments

Comments

@miguelpeixe
Copy link
Contributor

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

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

@ghost ghost assigned miguelpeixe May 1, 2012
@kukrapoke
Copy link

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 :
Can you help me please ?
Thanks !

@miguelpeixe
Copy link
Contributor Author

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
Copy link

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
Copy link
Contributor Author

Fixed it, thank you!

@aaronsmulktis
Copy link

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
Copy link

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
Copy link

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 :

Voila !
Thanks again to Miguel !

@aaronsmulktis
Copy link

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
Copy link

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
Copy link

sorry thank YOU kukrapoke for the speedy help! :P

@ghost
Copy link

ghost commented May 31, 2012

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
Copy link
Contributor Author

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
Copy link

ghost commented May 31, 2012

Ah! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants