Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Beyond the Theme - Using WordPress as an API


Published on

WordCamp Chicago 2011 slides for session

Published in: Technology, Business

Beyond the Theme - Using WordPress as an API

  1. 1. Beyond the Theme<br />Using WordPress as an API<br />
  2. 2. About Me<br />Find me on online at:<br />@davidscottufts<br /><br /><br /><br />I’m not a WordPress guru, ninja, black-belt, author, blogger, consultant, or hacker<br />I do use WordPress everywhere<br />
  3. 3. One Year of WordPress at Work<br />Migrated 14 unique brand sites and over 40 unique domains in 7 languages to WordPress multi-site<br />Our most popular brand’s average page views increased from 85,000 to 150,000 (over 130,000 daily emails, over 45,000 iPhone/iPad apps, and over 65,000 Facebook fans)<br />Our online donations increased by 38%<br />Reduced server footprint by 40% and our overhead costs decreased by 30%<br />Development time, costs, and learning curve for new developers were also all significantly reduced<br />
  4. 4. Goals of a WordPress Based Web Strategy<br />Have one install for multiple sites<br />Allow for a single sign-on across a network of sites<br />Use an API to allow for content to be easily accessible by other websites and mobile devices<br />Integrate web, social, mobile, social bookmarking, and monetization strategies<br />Aggregate and curate content from across the network of sites in one central stream<br />Think globally—location and language matter<br />
  5. 5. Why WordPress<br />It met the conditions of our web strategy<br />It has multi-site capabilities<br />It is open source (FREE)<br />It is easy to migrate to<br />It is easy to use<br />It is easy to install and upgrade<br />It is popular (15% of the web runs on WordPress)<br />It is versatile<br />
  6. 6. Versatile you say?<br />Extend it with themes and plugins<br />Modify it with hooks<br />Create custom post types<br />Add custom fields<br />Use custom taxonomies<br />Specify post formats<br />
  7. 7. An Analogy—Part 1<br />The WordPress admin area is like a kitchen and you are the chef<br />The WordPress plugins are like the kitchen appliances that make for a better cooking experience<br />The WordPress theme is like the dining room where the content is laid out for consumption<br />There is a one-to-one relationship between your content and its container, the theme<br />
  8. 8. Content vs. Container<br />A WordPress theme exists only within the context of its container—the web browser<br />Your content is consumed from within your website’s theme<br />Your RSS feed is the only way in which your content can be consumed from outside your website’s theme<br />
  9. 9. How Do People Find Your Site<br />Search engines index your content<br />Searches point people to your site<br />Users subscribe to your RSS feed<br />Friends might link to your site<br />Anyone can share your content on social networks<br />
  10. 10. Your Websites Current Sphere of Influence<br />
  11. 11. Introduction to APIs<br /> “An API (Application Programming Interface) is a way for two applications to talk to each other in a common language that both systems understand. An API essentially provides a structured way for applications to get content in a predictable, flexible, and powerful way.”<br />
  12. 12. Does WordPress have an API?<br />WordPress has XML-RPC for data management at the admin level<br />WordPress has multiple built-in APIs that allow developers to enhance WordPress through plugins and themes<br />WordPress has a robust query string that enables content filtering through the URL<br />WordPress has no end user API that allows for third-party development around your content<br />
  13. 13. What Can an API do for You?<br />Allows you to have a single instance of your content and users distributed across multiple channels<br />Allows developers to build third-party applications around your web-based content or service<br />Allows you to enhance the user experience within the context of your site by building an AJAX rich application<br />
  14. 14. Separating Content from Container<br />WordPress separates the admin and plugins from the theme<br />It allows for the content to exist independently of the website’s theme<br />Modifying a site’s theme does not impact your content<br />
  15. 15. An Analogy—Part 2<br />Same kitchen, chef, appliances, and dining room as the earlier analogy<br />An API turns your kitchen into a catering business with delivery trucks<br />There is a one-to-many relationship between your content and multiple containers: mobile apps, third-party websites, and social networks<br />
  16. 16. Adding an API to WordPress Expands Your Sphere of Influence<br />
  17. 17. 3 Simple Steps to Implementing an API into Your Next WordPress Theme<br />Pass additional query string parameters to the theme<br />Modify the theme to process API calls<br />Determine what format to return the content in<br />
  18. 18. Step 1: Pass Additional Query String Parameters to the Theme<br />Define a query string parameter to specify whether or not the request being made is an API call. Always default the parameter to false in the theme as to not disrupt non API requests (?api=true)<br />Define a query string parameter to specify in what format to return the content (&format=json)<br />
  19. 19. Step 2: Modify the Theme to Process API Calls<br /><?php<br /> $api = $_GET[‘api’];<br /> $f = $_GET[‘format’];<br />Section off the header and footer with conditional statements within files like index.php, single.php, archive.php, category.php, tag.php, and search.php<br />Evaluate based on the query string parameters if an API call needs the header and footer<br />If ( $api ) {<br /> // Conditional Header<br />}<br />// The Loop<br />get_template_part(‘loop’, $f);<br />If ( $api ) {<br /> // Conditional Footer<br />}<br />?><br />
  20. 20. Step 3: Determine What Format to Return the Content In<br />Create a series of loops in different formats to handle your custom API requests: loop-html5.php, loop-json.php, loop-xml.php<br />Allow the get_template_part() function to determine the appropriate format to use:get_template_part(‘loop’, $_GET[‘format’]);<br />
  21. 21. Example<br />You have built an events management WordPress theme using custom post types for events, sessions, speakers, attendees, and venues.<br />Now your conference attendees want to use their smart phones or tablets during an event to manage their schedules, rate sessions, etc. <br />
  22. 22. Allowing for Third-Party Development<br />Every new “app” is just another instance of a group of your users interacting with your content or service<br />Twitter would not be were it is today without an API which allows users and developers to interact with Twitter’s services on their terms<br />
  23. 23. Post Rank vs. Page Rank<br />The tide is changing from searchability to shareability<br />SEO is still be important, but what is more important is how accessible and shareable your content is from multiple devices, apps, and social networks<br />
  24. 24. Other API Implementation Ideas<br />Use the API calls for AJAX reloading from within the context of the WordPress theme<br />Use in conjunction with other query string parameters to determine the post type, posts per page, sort order, etc.<br />Be sure to output the correct headers to the browser in the cases where the requested formats are like JSON, XML, or downloadable files<br />
  25. 25. Write It Yourself or Use KickPress<br />The KickPressplugingives WordPress a public API for content distribution across multiple platforms and devices<br />Makes creating and using custom posts types and taxonomies easy<br />Focuses heavily on the publishing of a wide variety of content types (videos, books, events, reviews, authors, contacts, etc.)<br />Enables strong social media integration through a urlshortner, social sharing links, and a social sharing toolbar<br />Enables content aggregation from across the web into a local news feed<br />Enables content bookmarking by logged-in users<br />Extends WordPress through hooks, themes, and plugins, without the need to modify the core source code and/or database tables<br />
  26. 26. WP + API = { }<br />Beta release coming soon:<br />