Solved

PHP coding for Google Search

Posted on 2011-09-05
7
270 Views
Last Modified: 2012-05-12
Hi,

I would like to add a google custom search for the site http://secureinfo.info/ 
I want the search bar to appear in the right corner of the header section.

Attached is the current header.php file. If you need any other php file, please let me know.

Any help is appreciated as i do not know much about any php coding. I have the google code for the search bar and the search result page.

Thanks
header.php
0
Comment
Question by:ujitnos
  • 4
  • 3
7 Comments
 
LVL 8

Accepted Solution

by:
ropenner earned 500 total points
ID: 36482890
line 31 and 32 are...

<body <?php body_class(); ?>>

<?php


insert your code for the google search inbetween these two.  If it is PHP code then it is enclosed in <php ?> tags otherwise if it is HTML only then plop it in there.

To position it to the far top right you can use a table to contain it and absolute HTML positioning.  A sample of how it may appear in the header.php file is below... starting at line 31

<body <?php body_class(); ?>>
      <TABLE style="position:absolute; top:0px;right:5px">your stuff</TABLE>
<?php

code below is a working example placed right after the body tag

<html>

<body>

   <TABLE style="position:absolute; top:0px;right:5px">

   	<TR>

   		<TD> 

   			<SCRIPT language=javascript>

   				function addSite() {

   					var query = document.getElementById('q').value;

   					document.location.href="http://google.com/search?q="+query+"+site%3Asecurityinfo.info&hl=en&biw=1208&bih=685&num=10&lr=&ft=i&cr=&safe=images&tbs=";

   					return false;

   				}

				</SCRIPT>

   			<FORM onsubmit="javacript:return addSite();">

		   		<INPUT type=text size=20 id=q name=q>

		   	</FORM>

   		</TD>

   	</TR>

   </TABLE>

</BODY>

</HTML>

Open in new window

0
 
LVL 10

Author Comment

by:ujitnos
ID: 36483228
Ok, please review the page. I need to move it a bit down, in line with the title "Secure Info" How to?

I still not able to produce search results, but i will look into that.

This is what i inserted:-

<TABLE style="position:absolute; right:150px">
<form action="http://secureinfo.info/search-results" id="cse-search-box">
  <div>
    <input type="hidden" name="cx" value="partner-pub-80feferf823723193:gtfedsgzg3104" />
    <input type="hidden" name="cof" value="FORID:10" />
    <input type="hidden" name="ie" value="UTF-8" />
    <input type="text" name="q" size="55" />
    <input type="submit" name="sa" value="Search" />
  </div>
</form>
<script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&lang=en"></script>
</TABLE>
0
 
LVL 10

Author Comment

by:ujitnos
ID: 36483338
Hi, I also noticed that it is not aligned properly in Firefox
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 8

Expert Comment

by:ropenner
ID: 36483378
The form needs to be within a table row and data cell

you need to put
<TABLE>
<TR><TD>

  ... your stuff

</TD></TR>
</TABLE>
  otherwise it pushes the content outside of the table ... then you can play with the alignment

0
 
LVL 10

Author Comment

by:ujitnos
ID: 36483466
Ok, thanks, got that right. Now how do i move it a bit down ?
0
 
LVL 8

Assisted Solution

by:ropenner
ropenner earned 500 total points
ID: 36485253
add to your table's style how far from the TOP of the screen you want it to appear.  It is in the original post's code as well


eg.
style="position:absolute; top:20px; right:50px"
0
 
LVL 10

Author Closing Comment

by:ujitnos
ID: 36500614
Thanks
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question