[{"ID":126,"post_author":"1","post_date":"2012-02-26 20:25:33","post_date_gmt":"2012-02-26 20:25:33","post_content":"<img src=\"http:\/\/bb3.local\/inc\/json\/wp-content\/uploads\/2012\/02\/theme-icon.png\" alt=\"\" title=\"BBID JSON Icon\" width=\"300\" height=\"225\" class=\"alignright size-full wp-image-189\" \/>Here is the WordPress theme I made for rendering JSON that's currently being used on this site. This Theme allows you to use WordPress as a CMS and data provider for AJAX or other web apps. This is nice if you want to escape from the WordPress \"Loop\" and their Template API. Unfortunately I am not able to submit the Theme to the WordPress Theme Gallery since it is not a legitimate Theme in the sense that Themes render HTML and have widgets and other features that are required in the submission guidelines. In hindsight, I realized that this would probably have been better created as a Plugin.\r\n\r\nSpeaking of Plugins, the nerds over at MOMA made a really cool \"REST-style\" <a href=\"http:\/\/wordpress.org\/extend\/plugins\/json-api\/\">JSON API plugin<\/a> for WordPress that supports submitting comments and handling user registrations in addition to retrieving content. Obviously their pimp hand is much stronger than mine. \r\n\r\n<h3>Download<\/h3>\r\nBBID JSON WordPress theme v1.0: <a href=\"\/inc\/json\/wp-content\/uploads\/2012\/02\/bbidjson-1.0.zip\">Download<\/a>\r\n\r\n<h3>Documentation<\/h3>\r\n\r\n<h4>Usage<\/h4>\r\nURLs to the Theme work the same as with any WordPress install. If you want a list of your recent Posts returned into your javascript, just send an <code><a href=\"http:\/\/api.jquery.com\/jQuery.ajax\/\">AJAX<\/a><\/code> HTTP call to the location of your WordPress installation.  To get the same as a PHP object into your PHP script, use <code><a href=\"http:\/\/php.net\/manual\/en\/function.file-get-contents.php\">file_get_contents<\/a><\/code> with <code><a href=\"http:\/\/php.net\/manual\/en\/function.json-decode.php\">json_decode<\/a><\/code>. Here are some example URLs:\r\n<ul>\r\n<li>Get JSON of Category: <code>http:\/\/my-site.com\/install-path\/category\/apples<\/code><\/li>\r\n<li>Get JSON of a Page: <code>http:\/\/my-site.com\/install-path\/my-page-slug<\/code><\/li>\r\n<li>If you don't have permalinks: <code>http:\/\/my-site.com\/install-path\/?p=123<\/code><\/li>\r\n<\/ul>\r\nSince WordPress relies on either <code>.htaccess<\/code> files for permalink or querystring for shortlink (<code>?p=123<\/code>) to retrieve content, the requests must be sent over HTTP. \r\n\r\n<h4>Special Templates<\/h4>\r\nAs of this writing, the Special Templates only work with permalinks enabled (Settings->Permalinks in the WordPress Admin).\r\n\r\n<h5>Get Blog Info<\/h5>\r\nThere are a two Templates that are included in the theme. The first is a file named <code>_get-blog-info.php<\/code>, which will show up as <strong>Get Blog Info<\/strong> in the WordPress Admin in the Pages->Edit->Template dropdown. \r\n\r\nTo use this Special Template with the Theme, create a Page and set it as the <strong>Get Blog Info<\/strong> Template. The way to access this page is through the permalink or shortlink. For this example, let's assume we create the permalink as <code>get-blog-info<\/code>. Then we access the page using a URL like so: <code>http:\/\/my-site.com\/install-path\/get-blog-info?name;description;admin_email<\/code>\r\n\r\nThe querystring will contain a semicolon delimited list of blog info parameters to return in the JSON object. The parameters are typically for fields that are set in the WordPress Admin in Settings->General in addition to some technical information about the WordPress installation. For all the available parameters, see: <a href=\"http:\/\/codex.wordpress.org\/Function_Reference\/get_bloginfo\">http:\/\/codex.wordpress.org\/Function_Reference\/get_bloginfo<\/a>\r\n\r\n<h5>Get Menu<\/h5>\r\nThis template file in the Theme is <code>_get-menu.php<\/code> and will show up as <strong>Get Menu<\/strong> in the WordPress Admin. To use the template, follow the steps outlined for <strong>Get Blog Info<\/strong> above. Let's assume our permalink for the Page using the <strong>Get Menu<\/strong> Template is <code>get-menu<\/code>. You can now get a JSON object of the <strong>Primary Menu<\/strong> (which has key <code>menu1<\/code>) by using a URL like so: <code>http:\/\/my-site.com\/install-path\/get-menu?menu1<\/code>\r\n\r\nIn the WordPress Admin, you can set custom menus in Appearance->Menus. There are three menus in the Theme and they are retrieved by <strong>Theme Location<\/strong> and <strong>NOT<\/strong> by the Menu Name. This is done so that you can update and swap out different menus without needing to recode any of the theme or any of your web app. Here are the three Menu Locations and their keys:\r\n<ul>\r\n<li>Primary: <code>menu1<\/code>\r\n<li>Secondary: <code>menu2<\/code>\r\n<li>Tertiary: <code>menu3<\/code>\r\n<\/ul>\r\nMore Menus can be added toward the bottom of the <code>functions.php<\/code> file if desired. For more information, see <a href=\"http:\/\/codex.wordpress.org\/Function_Reference\/register_nav_menus\">http:\/\/codex.wordpress.org\/Function_Reference\/register_nav_menus<\/a>\r\n\r\n\r\n","post_title":"BBID JSON WordPress Theme","post_excerpt":"","post_status":"publish","comment_status":"open","ping_status":"open","post_password":"","post_name":"bbid-json-wordpress-theme","to_ping":"","pinged":"","post_modified":"2012-03-19 01:47:23","post_modified_gmt":"2012-03-19 01:47:23","post_content_filtered":"","post_parent":0,"guid":"http:\/\/bb3.bradbarwick.com\/inc\/json\/?page_id=126","menu_order":0,"post_type":"page","post_mime_type":"","comment_count":"0","filter":"raw","post_uri":"\/bbid-json-wordpress-theme","comments_count":{"approved":0,"spam":0,"trash":0,"post-trashed":0,"total_comments":0,"all":0,"moderated":0},"post_categories":[],"post_html":"<p><img loading=\"lazy\" src=\"http:\/\/bb3.local\/inc\/json\/wp-content\/uploads\/2012\/02\/theme-icon.png\" alt=\"\" title=\"BBID JSON Icon\" width=\"300\" height=\"225\" class=\"alignright size-full wp-image-189\" \/>Here is the WordPress theme I made for rendering JSON that&#8217;s currently being used on this site. This Theme allows you to use WordPress as a CMS and data provider for AJAX or other web apps. This is nice if you want to escape from the WordPress &#8220;Loop&#8221; and their Template API. Unfortunately I am not able to submit the Theme to the WordPress Theme Gallery since it is not a legitimate Theme in the sense that Themes render HTML and have widgets and other features that are required in the submission guidelines. In hindsight, I realized that this would probably have been better created as a Plugin.<\/p>\n<p>Speaking of Plugins, the nerds over at MOMA made a really cool &#8220;REST-style&#8221; <a href=\"http:\/\/wordpress.org\/extend\/plugins\/json-api\/\">JSON API plugin<\/a> for WordPress that supports submitting comments and handling user registrations in addition to retrieving content. Obviously their pimp hand is much stronger than mine. <\/p>\n<h3>Download<\/h3>\n<p>BBID JSON WordPress theme v1.0: <a href=\"\/inc\/json\/wp-content\/uploads\/2012\/02\/bbidjson-1.0.zip\">Download<\/a><\/p>\n<h3>Documentation<\/h3>\n<h4>Usage<\/h4>\n<p>URLs to the Theme work the same as with any WordPress install. If you want a list of your recent Posts returned into your javascript, just send an <code><a href=\"http:\/\/api.jquery.com\/jQuery.ajax\/\">AJAX<\/a><\/code> HTTP call to the location of your WordPress installation.  To get the same as a PHP object into your PHP script, use <code><a href=\"http:\/\/php.net\/manual\/en\/function.file-get-contents.php\">file_get_contents<\/a><\/code> with <code><a href=\"http:\/\/php.net\/manual\/en\/function.json-decode.php\">json_decode<\/a><\/code>. Here are some example URLs:<\/p>\n<ul>\n<li>Get JSON of Category: <code>http:\/\/my-site.com\/install-path\/category\/apples<\/code><\/li>\n<li>Get JSON of a Page: <code>http:\/\/my-site.com\/install-path\/my-page-slug<\/code><\/li>\n<li>If you don&#8217;t have permalinks: <code>http:\/\/my-site.com\/install-path\/?p=123<\/code><\/li>\n<\/ul>\n<p>Since WordPress relies on either <code>.htaccess<\/code> files for permalink or querystring for shortlink (<code>?p=123<\/code>) to retrieve content, the requests must be sent over HTTP. <\/p>\n<h4>Special Templates<\/h4>\n<p>As of this writing, the Special Templates only work with permalinks enabled (Settings->Permalinks in the WordPress Admin).<\/p>\n<h5>Get Blog Info<\/h5>\n<p>There are a two Templates that are included in the theme. The first is a file named <code>_get-blog-info.php<\/code>, which will show up as <strong>Get Blog Info<\/strong> in the WordPress Admin in the Pages->Edit->Template dropdown. <\/p>\n<p>To use this Special Template with the Theme, create a Page and set it as the <strong>Get Blog Info<\/strong> Template. The way to access this page is through the permalink or shortlink. For this example, let&#8217;s assume we create the permalink as <code>get-blog-info<\/code>. Then we access the page using a URL like so: <code>http:\/\/my-site.com\/install-path\/get-blog-info?name;description;admin_email<\/code><\/p>\n<p>The querystring will contain a semicolon delimited list of blog info parameters to return in the JSON object. The parameters are typically for fields that are set in the WordPress Admin in Settings->General in addition to some technical information about the WordPress installation. For all the available parameters, see: <a href=\"http:\/\/codex.wordpress.org\/Function_Reference\/get_bloginfo\">http:\/\/codex.wordpress.org\/Function_Reference\/get_bloginfo<\/a><\/p>\n<h5>Get Menu<\/h5>\n<p>This template file in the Theme is <code>_get-menu.php<\/code> and will show up as <strong>Get Menu<\/strong> in the WordPress Admin. To use the template, follow the steps outlined for <strong>Get Blog Info<\/strong> above. Let&#8217;s assume our permalink for the Page using the <strong>Get Menu<\/strong> Template is <code>get-menu<\/code>. You can now get a JSON object of the <strong>Primary Menu<\/strong> (which has key <code>menu1<\/code>) by using a URL like so: <code>http:\/\/my-site.com\/install-path\/get-menu?menu1<\/code><\/p>\n<p>In the WordPress Admin, you can set custom menus in Appearance->Menus. There are three menus in the Theme and they are retrieved by <strong>Theme Location<\/strong> and <strong>NOT<\/strong> by the Menu Name. This is done so that you can update and swap out different menus without needing to recode any of the theme or any of your web app. Here are the three Menu Locations and their keys:<\/p>\n<ul>\n<li>Primary: <code>menu1<\/code>\n<li>Secondary: <code>menu2<\/code>\n<li>Tertiary: <code>menu3<\/code>\n<\/ul>\n<p>More Menus can be added toward the bottom of the <code>functions.php<\/code> file if desired. For more information, see <a href=\"http:\/\/codex.wordpress.org\/Function_Reference\/register_nav_menus\">http:\/\/codex.wordpress.org\/Function_Reference\/register_nav_menus<\/a><\/p>\n","custom_fields":{"display_template":"body-text"},"media_attachments":[{"description":"","title":"BBID JSON WordPress Theme download archive","caption":"","mime_type":"application\/zip","url":"https:\/\/bb3-content.bradbarwick.com\/wp-content\/uploads\/2012\/02\/bbidjson-1.0.zip"},{"description":"","title":"BBID JSON Icon","caption":"","mime_type":"image\/png","images":{"thumbnail":{"url":"https:\/\/bb3-content.bradbarwick.com\/wp-content\/uploads\/2012\/02\/theme-icon-120x120.png","width":120,"height":120},"medium":{"url":"https:\/\/bb3-content.bradbarwick.com\/wp-content\/uploads\/2012\/02\/theme-icon.png","width":300,"height":225},"medium_large":{"url":"https:\/\/bb3-content.bradbarwick.com\/wp-content\/uploads\/2012\/02\/theme-icon.png","width":300,"height":225},"large":{"url":"https:\/\/bb3-content.bradbarwick.com\/wp-content\/uploads\/2012\/02\/theme-icon.png","width":300,"height":225},"1536x1536":{"url":"https:\/\/bb3-content.bradbarwick.com\/wp-content\/uploads\/2012\/02\/theme-icon.png","width":300,"height":225},"2048x2048":{"url":"https:\/\/bb3-content.bradbarwick.com\/wp-content\/uploads\/2012\/02\/theme-icon.png","width":300,"height":225},"project_thumbnail":{"url":"https:\/\/bb3-content.bradbarwick.com\/wp-content\/uploads\/2012\/02\/theme-icon-300x200.png","width":300,"height":200},"tiny_thumbnail":{"url":"https:\/\/bb3-content.bradbarwick.com\/wp-content\/uploads\/2012\/02\/theme-icon-60x60.png","width":60,"height":60},"full":{"url":"https:\/\/bb3-content.bradbarwick.com\/wp-content\/uploads\/2012\/02\/theme-icon.png","width":300,"height":225}}}],"post_thumbnails":{"full":false,"large":false,"medium":false,"thumbnail":false}}]