Jump to content

How to add search tips at blocksearch


Recommended Posts

My idea was to add randomly generated search tips just after top search input (just like in attached screenshot file) using standard blocksearch module.

To do this we need to:

1) Modify blocksearch-top.tpl like this:

<div id="search_block_top" class="col-sm-4 clearfix pull-left">
  <form method="get" action="{$link->getPageLink('search')}" id="searchbox" class="searchtop">
   <label for="search_query_top"><!-- image on background --></label>
   <input type="hidden" name="controller" value="search" />
   <input type="hidden" name="orderby" value="position" />
   <input type="hidden" name="orderway" value="desc" />
   <input class="search_query" type="text" id="search_query_top" name="search_query" placeholder="{l s='Looking for?' mod='blocksearch'}" value="{if isset($smarty.get.search_query)}{$smarty.get.search_query|htmlentities:$ENT_QUOTES:'utf-8'|stripslashes}{/if}" />
   <input type="submit" name="submit_search" value="{l s='Search' mod='blocksearch'}" class="button search-button" />
   <div class="search_comment" style="color: #999;">
    {l s='For example:' mod='blocksearch'}  
    <span id="search-example" class="search_example" style="text-decoration: underline; cursor: pointer;"></span>
   </div>
  <script type="text/javascript">
   $.get('/rand.php', function(data){
   $('#search-example').text(data);
   $('#search-example').click(function(){
   var SearchInput = $('#search_query_top');
   SearchInput.val(data);
   var strLength= SearchInput.val().length;
   SearchInput.focus();
   SearchInput[0].setSelectionRange(strLength, strLength);
   SearchInput.trigger('keydown');
   });
   });
  </script>
  </form>
 </div>

 

2) create file rand.php in root directory with this content

 

<?php
$selPhrase = array('Good1','Good2','Good3');
echo $selPhrase[rand(0,2)];
?>

 

where 0 and 2 in echo $selPhrase[rand(0,2)]; are the $selPhrase array dimensions.

Instead of 'Good1' there can be either full/part of product title, description etc.

 

post-720294-0-70543700-1407955569_thumb.png

Link to comment
Share on other sites

×
×
  • Create New...