Wordpress Themes - WP Forum at BFA

Wordpress Themes - WP Forum at BFA (http://forum.bytesforall.com/index.php)
-   Header configuration & styling (http://forum.bytesforall.com/forumdisplay.php?f=15)
-   -   Add Google CSE Code and enable a Google custom search (http://forum.bytesforall.com/showthread.php?t=20680)

dherrhoyman Jul 23, 2013 10:17 AM

Add Google CSE Code and enable a Google custom search
 
After having gone around on how Atahualpa works and Google CSE works (today),
I have hacked my theme to get a search to work out of the header.
Pretty sure I could add in another theme edit variable (the Google CSE code)
and make it add in the relevant bits. This would be if you had the header search box ON,
then if this yet-to-be-added setting where defined (not blank), it would add in the relevent
bits. This is partly for my own self interest (don't want the next update to blow away
my changes) and partly a contribution so others don't have to do this hack.

I think I can figure this out or would follow the directions on what's kosher
in added such a setting. I can also explain how to make a search results page
work too. See http://snapplus.wisc.edu for what I have going now.

Done things like this before in Moodle and Joomla.
Shoot I'd just edit the Atahualpa source code, if I were made a committer.
Or I could do a diff and send it to whomever.
Just let me know!

--Dirk Herr-Hoyman

juggledad Jul 23, 2013 12:00 PM

Why not try one of the google CSE plugins?

dherrhoyman Jul 23, 2013 12:21 PM

That only gets you part way there.
I am using the Google Custom Search plugin, but the
search in the header doesn't switch to the CSE.
I have hacked it in by directly modifying bfa_header_config.php (see below).
If the <insert CSE code> had a theme setting variable, and there was another if/then,
it would work:

// Search box
if ( $bfa_ata['show_search_box'] == "Yes" )
{

/*
echo '<td valign="bottom" class="search-box" align="right"><div class="searchbox">
<form method="get" class="searchform" action="' . $homeURL . '/">
<div class="searchbox-form">' .
// Since 3.6.8: Removed check whether get_search_query() exists and added esc_js
'<input type="text" class="text inputblur" onfocus="this.value=\'' .
( get_search_query() ? esc_js(get_search_query()) : '' ) . '\'"
value="' . ( get_search_query() ? esc_js(get_search_query()) : esc_attr($bfa_ata['searchbox_text']) ) .
'" onblur="this.value=\'' . ( get_search_query() ? esc_js(get_search_query()) :
esc_attr($bfa_ata['searchbox_text']) ) . '\'" name="s" />' .
'</div>
</form>
</div>
</td>';
*/
/**/
echo '<td valign="bottom" class="search-box" align="right"><div class=searchbox><div>' .
'<script>
(function() {
var cx = "<insert CSE code here>";
var gcse = document.createElement("script");
gcse.type = "text/javascript";
gcse.async = true;
gcse.src = (document.location.protocol == "https:" ? "https:" : "http:") +
"//www.google.com/cse/cse.js?cx=" + cx;
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(gcse, s);
})();
</script>
<gcse:searchbox-only></gcse:searchbox-only>' .
'</div></div></tr>
';
/**/
}


All times are GMT -6. The time now is 03:28 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.