wordpress & a mobile app

26
& A Mobile App Amit Sharma, 13 Llama Studio +AmitSharma13l @hypnosh #WCMumbai

Upload: amit-sharma

Post on 16-Jul-2015

118 views

Category:

Software


0 download

TRANSCRIPT

Page 1: WordPress & A Mobile App

& A Mobile App

Amit Sharma, 13 Llama Studio +AmitSharma13l @hypnosh

#WCMumbai

Page 2: WordPress & A Mobile App

32% 26%

20%

93% 89% 87%

5% 6%

2012 2013 2014

Page 3: WordPress & A Mobile App

Social Marketplace

Page 4: WordPress & A Mobile App

A Social Network for Architects

Page 5: WordPress & A Mobile App

Recruitment Tool for an Insurance Company

Page 6: WordPress & A Mobile App

What next?

A mobile app maybe?

Page 7: WordPress & A Mobile App

Is WordPress MVC?

J

Page 8: WordPress & A Mobile App

M

V

C

Custom Post Type (CPT)

functions.php & Hooks

WordPress Theme HTML5 iOS app Android app

AJAX / WP REST API

Page 9: WordPress & A Mobile App

AJAX / WP REST API

Page 10: WordPress & A Mobile App

Creating CPTs register_post_type( ‘model’, $args );

Page 11: WordPress & A Mobile App

Attributes: Custom Fields

Page 12: WordPress & A Mobile App

CRUD

Page 13: WordPress & A Mobile App

Create wp_insert_post( $post );

Page 14: WordPress & A Mobile App

Read List

get_posts( $args );

View get_post( $id );

get_post_meta( $id, $key );

Page 15: WordPress & A Mobile App

Update

wp_update_post( $post );

add_post_meta( $id, $key, $value );

update_post_meta( $id, $key, $value );

delete_post_meta( $id, $key, $value );

Page 16: WordPress & A Mobile App

Delete wp_delete_post( $id );

Page 17: WordPress & A Mobile App

Controller functions.php Action Hooks

Page 18: WordPress & A Mobile App

Action Hooks add_action( $hook, $function );

Page 19: WordPress & A Mobile App

AJAX add_action( ‘wp_ajax_theajaxhook’, ‘the_function’

); add_action( ‘wp_ajax_nopriv_theajaxhook’, ‘the_function’

);

Page 20: WordPress & A Mobile App

add_action(‘wp_ajax_nopriv_myhook’, ‘myfunction’); function myfunction() {

$mydata = $_REQUEST[‘mydata’]; $result = do_something($mydata); echo json_encode($result); die();

}

$.ajax({ url: '/wp/wp-admin/admin-ajax.php', type: ‘GET', data: { action: ’myhook’, mydata: ‘some data’ })

.done(function(response) { // jQuery.parseJSON(response) is $result

});

V

C

functions.php

jQuery

Page 21: WordPress & A Mobile App

Handlebar <script id=’tmpl1' type='text/x-handlebars-template'> <ul>

{{#each response.Items}} <li data-icon='false' id='event-{{ ID }}’> <span class='list-date'>{{{ e_date }}}</span> <span class='list-title'>{{ post_title }}</span><br> <span class='line-2'>{{{ post_content }}}</span> <button data-eventid="{{ ID }}"></button> </li> {{/each}}

</ul> </script>

Page 22: WordPress & A Mobile App

REST API & JSON POST /posts GET /posts GET /posts/id GET /posts/id/meta POST /posts/id/meta PUT /posts/id/meta/mid DELETE /posts/id/meta/mid

Create:

List: View:

Update:

Delete:

Page 23: WordPress & A Mobile App
Page 24: WordPress & A Mobile App
Page 25: WordPress & A Mobile App
Page 26: WordPress & A Mobile App

https://github.com/WordCampMum/2015/blob/master/Amit-Sharma-WordPress-as-Backbone-for-a-Mobile-App.md