Solved

PHP coding for Google Search

Posted on 2011-09-05
7
283 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

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…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
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)

729 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