{"id":280,"date":"2008-12-14T23:39:36","date_gmt":"2008-12-15T05:39:36","guid":{"rendered":"http:\/\/www.cyberward.net\/blog\/?p=280"},"modified":"2009-01-25T11:28:30","modified_gmt":"2009-01-25T17:28:30","slug":"integrating-with-wordpress","status":"publish","type":"post","link":"https:\/\/www.cyberward.net\/blog\/2008\/12\/integrating-with-wordpress\/","title":{"rendered":"Integrating with WordPress"},"content":{"rendered":"<p>I probably should be working on the 2.7 upgrade, but instead I started looking at photo gallery options other than <a href=\"http:\/\/gallery.menalto.com\/\">Gallery2<\/a>. It is just too slow. There is too much of it I don&#8217;t use as well. I think I have settled on <a href=\"http:\/\/www.zenphoto.org\/\">zenphoto<\/a>. It seems to work pretty well, with out the feature creep that Gallery2 has. I figured I would convert the <a href=\"http:\/\/annieandchris.net\">annieandchris.net<\/a> site to that.<\/p>\n<p>It got me thinking though about how I might integrate it with WordPress. After seeing the tantan <a href=\"http:\/\/tantannoodles.com\/toolkit\/photo-album\/\">Flickr<\/a> plugin, and how well it works, I figured that there must be a plugin for zenphoto. Well, no. Not really. There are a couple that will let you show pictures in the sidebar. And Trung&#8217;s <a href=\"http:\/\/trunghuynh.com\/2008\/07\/trung_presszen-094\/\">presszen<\/a> looked promising, but it didn&#8217;t seem to work. I started taking a look at the code for the tantan Flicker plugin, and saw how he was able to take control of a URI to insert his own code in with the current wordpress theme. I stripped out the relevant stuff, and got it to work. This is the code.<\/p>\n<pre lang=\"php\">\r\nfunction parse_query(&amp;$query) {\r\n\t$query-&gt;is_404 = false;\r\n\t$query-&gt;did_permalink = false;\r\n}\r\nfunction request($query_vars) {\r\n    $query_vars['error'] = false;\r\n    return $query_vars;\r\n}\r\n\r\nfunction cww_template() {\r\n\tget_header();\r\n\techo '\r\n<div id=\"content\" class=\"narrowcolumn\">\r\n<h2>Zen Integration<\/h2>\r\n<\/div>\r\n';\r\n\tget_footer();\r\n\texit;\r\n}\r\n\r\ndefine(\"CWW_ZEN_BASEURL\", \"\/blog\/test\");\r\nif (strpos($_SERVER['REQUEST_URI'], CWW_ZEN_BASEURL) === 0) {\r\n    status_header(200);\r\n    remove_action('template_redirect', 'redirect_canonical');\r\n    add_filter('request', 'request');\r\n    add_action('parse_query', 'parse_query');\r\n    add_action('parse_request', 'parse_query');\r\n    add_action('template_redirect', 'cww_template');\r\n} elseif (strpos($_SERVER['REQUEST_URI'].'\/', CWW_ZEN_BASEURL) === 0) {\r\n    header('location: http:\/\/'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].'\/');\r\n    exit;\r\n}\r\n?>\r\n<\/pre>\n<p>I think that I may take a go at pulling in the zenphoto albums in a plugin, and see how it goes. I like how you create plugins in WordPress, and it is kind of fun poking around. It was frustrating for the longest time when I was trying to get it going, and I was getting the body of the blog showing up at the bottom. I finally realized that I needed to &#8216;exit&#8217; the script to prevent the loop from happening. You would think you could override a WordPress function to prevent that instead.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I probably should be working on the 2.7 upgrade, but instead I started looking at photo gallery options other than Gallery2. It is just too slow. There is too much of it I don&#8217;t use as well. I think I &hellip; <a href=\"https:\/\/www.cyberward.net\/blog\/2008\/12\/integrating-with-wordpress\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[101],"tags":[108,109,106,15,110],"series":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pffAy-4w","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/posts\/280"}],"collection":[{"href":"https:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/comments?post=280"}],"version-history":[{"count":0,"href":"https:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/posts\/280\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/media?parent=280"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/categories?post=280"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/tags?post=280"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/series?post=280"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}