ThemeShaper Forums » Thematic

[closed]

Replacing Wordpress search with Google

(5 posts)
  • Started 2 years ago by Nate H
  • Latest reply from helgatheviking
  • This topic is not resolved
  1. Nate H
    Member

    Aloha,
    I have been trying to get Google search results on my webpage and seem to be missing something. I have found no plugin that will work, because google recently changed their Custom Google Search Control panel to not have an iframe option.

    I thought I was getting somewhere with this article, but it seems like Thematic overrides the search results page: http://iamtgc.com/2011/07/10/integrating-a-google-custom-search-engine-into-your-wordpress-blog/

    Any insight would be very much appreciated.

    Thank You,
    Nate

    Posted 2 years ago #
  2. thematic_search_form() is the form

    and

    thematic_searchloop() is the results

    don't know if that helps

    Posted 2 years ago #
  3. Nate H
    Member

    Thank you for the help!

    I found this tutorial:
    http://www.newtechie.com/2011/11/how-to-add-google-custom-search-to.html#axzz1fmuG5yr5

    Which uses the Two Page layout method. I get a 404'd when I tried getting it to work.

    Here is my latest attempt, that isn't working, at removing the Thematic loop and adding the google code within the functions.

    // remove the standard search loop
    function remove_search_loop() {
    	remove_action('thematic_searchloop', 'thematic_search_loop');
    }
    add_action('wp', 'remove_search_loop');
    // create your own search loop
    
    function my_search_loop() {
    // Your content goes in here
     <?php if ( have_posts() ) : ?>
    <div id="cse" style="width: 100%;">Loading</div>
    <script src="//www.google.com/jsapi" type="text/javascript"></script>
    <script type="text/javascript">
      function parseQueryFromUrl () {
        var queryParamName = "s";
        var search = window.location.search.substr(1);
        var parts = search.split('&');
        for (var i = 0; i < parts.length; i++) {
          var keyvaluepair = parts[i].split('=');
          if (decodeURIComponent(keyvaluepair[0]) == queryParamName) {
            return decodeURIComponent(keyvaluepair[1].replace(/\+/g, ' '));
          }
        }
        return '';
      }
    
      google.load('search', '1', {language : 'en', style : google.loader.themes.MINIMALIST});
      google.setOnLoadCallback(function() {
        var customSearchControl = new google.search.CustomSearchControl(
          'XXXXXXXXXXXXXXXXXXXXXX');
    
        customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
        customSearchControl.draw('cse');
        var queryFromUrl = parseQueryFromUrl();
        if (queryFromUrl) {
          customSearchControl.execute(queryFromUrl);
        }
      }, true);
    </script>
    <?php endif; ?>
    add_action('thematic_searchloop', 'my_search_loop');
    Posted 2 years ago #
  4. Nate H
    Member

    I must be missing something. Is there a tutorial for adding a Google Custom Search to Thematic?

    Thanks again for the help.

    Posted 2 years ago #
  5. no tutorials that i know of. your code for replacing the search loop looks fine. however, if you are getting a 404 then your loop isn't the problem.

    Posted 2 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.