{"id":1170,"date":"2010-09-06T21:16:36","date_gmt":"2010-09-06T20:16:36","guid":{"rendered":"http:\/\/www.codingfriends.com\/?p=1170"},"modified":"2010-09-06T21:18:07","modified_gmt":"2010-09-06T20:18:07","slug":"custom-wordpress-page-on-a-new-url","status":"publish","type":"post","link":"https:\/\/www.codingfriends.com\/index.php\/2010\/09\/06\/custom-wordpress-page-on-a-new-url\/","title":{"rendered":"Custom wordpress page on a new URL"},"content":{"rendered":"<p>I liked to have the idea of having google search my site and have it displayed within my current site design, and since <a href=\"http:\/\/wordpress.org\/\">wordpress<\/a> allows to have <a href=\"http:\/\/codex.wordpress.org\/Plugin_API\/Action_Reference\">action hooks<\/a> that allow you to interrupt the present flow of generating the wordpress outputted page.<\/p>\n<p>So to have the google searched and display results within the style that I am using I first needed to create a plugin, if you create a file within your <\/p>\n<p>wordpress base directory\/wp-content\/plugins\/codingfriendsgooglesearch<\/p>\n<p>within the file below within the that directory created above, (I saved this file as googlesearch.php, but it does not matter as long as it is a .php file with the plugin details at the top of the file between the \/*&#8230; *\/ parts.<\/p>\n<pre lang=\"php\">\r\n<?php\r\n\/*\r\nPlugin Name: Google search page\r\nPlugin URI: http:\/\/www.codingfriends.com\r\nDonate link: http:\/\/www.codingfriends.com\r\nDescription: Google search page\r\nVersion: 0.1\r\nAuthor: Ian Porter\r\nAuthor URI: http:\/\/www.codingfriends.com\r\n*\/\r\n\r\nfunction get_requested_uri() {\r\n       $requesturi = $_SERVER['REQUEST_URI'];\r\n       if (substr($requesturi, -1)!=\"\/\") {\r\n               $requesturi = $requesturi.\"\/\";\r\n       }\r\n       preg_match_all('#[^\/]+\/#', $requesturi, $matches);\r\n       $uri = $matches[0];\r\n       return $uri;\r\n}\r\n\r\nfunction google_search_display() {\r\n       $uri = get_requested_uri();\r\n       if ($uri[0]=='googlesearch\/') {\r\n               include(TEMPLATEPATH . '\/googlesearch.php');\r\n               exit;\r\n               }\r\n}\r\n\r\nadd_action( 'template_redirect', 'google_search_display');\r\n\r\n?><\/pre>\n<p>What basically happens is when the template_redirect is called, this is when most of the processing of the page has already been done, and we are about to display the requested page from the blog, well in this case I would like to add function call to google_search_display, which is within this same file, and what it does is to search for &#8216;googlesearch\/&#8217; within the first part of the URL requested e.g.<\/p>\n<pre lang=\"html4strict\">\r\nhttp:\/\/www.codingfriends.com\/googlesearch\/\r\n<\/pre>\n<p>and if so display the googlesearch.php php file from within the templates directory, and here is my googlesearch.php file, and it displays the content within the div tag with cse-search-results, with the present style around the google search results.<\/p>\n<pre lang=\"php\">\r\n<?php get_header(); ?>\r\n<div id=\"content\" class=\"narrowcolumn\" role=\"main\">\r\n<div id=\"cse-search-results\"><\/div>\r\n<script type=\"text\/javascript\">\r\n var googleSearchIframeName = \"cse-search-results\";\r\n var googleSearchFormName = \"cse-search-box\";\r\n var googleSearchFrameWidth = 795;\r\n var googleSearchDomain = \"www.google.co.uk\";\r\n var googleSearchPath = \"\/cse\";\r\n<\/script>\r\n<script type=\"text\/javascript\"\r\nsrc=\"http:\/\/www.google.com\/afsonline\/show_afs_search.js\"><\/script>\r\n<\/div>\r\n<?php get_sidebar(); ?>\r\n<?php get_footer(); ?>\r\n<\/pre>\n<p>wordpress is really nice where you are able to alter the present execution process.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I liked to have the idea of having google search my site and have it displayed within my current site design, and since wordpress allows to have action hooks that allow you to interrupt the present flow of generating the wordpress outputted page. So to have the google searched and display results within the style &hellip; <a href=\"https:\/\/www.codingfriends.com\/index.php\/2010\/09\/06\/custom-wordpress-page-on-a-new-url\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Custom wordpress page on a new URL<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[275,276,408],"class_list":["post-1170","post","type-post","status-publish","format-standard","hentry","category-php","tag-action-hook","tag-google-search","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/1170","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/comments?post=1170"}],"version-history":[{"count":2,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/1170\/revisions"}],"predecessor-version":[{"id":1172,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/1170\/revisions\/1172"}],"wp:attachment":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/media?parent=1170"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/categories?post=1170"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/tags?post=1170"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}