Search Box Duplicate Results

Permalink 6 users found helpful
Can anyone help me please, ive added a search box and managed to get it to pull results in my main page but for some reason its outputting the results under the search box ive created as well

is there anyway i can fix this and stop it showing it ?

you will see what i mean here if you do a search in the top box

http://www.mountainmomentum.co.uk/index.php...

 
JohntheFish replied on at Permalink Reply
JohntheFish
(continuing fromhttp://www.concrete5.org/community/forums/themes/search-and-other-b...

You can create an alternate view template and use it just for the first search block in your menu. Leave the block on the main area of the search page to show the results.

http://www.concrete5.org/documentation/how-tos/developers/change-th...
jero replied on at Permalink Reply
jero
I'm doing this in my 5.4.2.2 template:

if (!isset($_GET['search_paths'])){
    $search = BlockType::getByHandle('search');
    $search->controller->title = 'Site Search';
    $search->controller->buttonText = 'Search';
    $search->controller->baseSearchPath = '';
    $search->controller->resultsURL = DIR_REL.'/search/search-results';
    $search->render('view');
}


I.E. I only show the search block if there are no results. Because I have dropped another search block into the results page, the one in the header can be hidden

Another option might be to add a CSS rule that targets the search results in your page header, and sets them to "display:none". They're still there, but no one will ever know ;)
liamb2001 replied on at Permalink Reply
John, not sure if ive been looking at code too long today but i dont really understand the method you mention, id appreciate if you eloborate me and my tired mind

Jero, seemed like a great idea so i tried it and it dissapeared in the header and on the main page, it seems as if both get the information from the same source, would there be any way around that at all do you know ??
jero replied on at Permalink Reply
jero
In my case, the search block in the header is coded into the template as per the example above. The one in the page is added to the page area in the usual way, so they're different.

The results output is contained within a
<div id="searchResults">


div tag. There are going to be two with the same ID, which is actually a bit naughty, but it your css looks like this

div#header div#searchResults {display:none} where div#header refers to a div with id=header then that ought to work, I would have thought?
liamb2001 replied on at Permalink Reply
hi jero, from what i can see the header and the main use the view.php to get the info from the view.css in the /blocks/search folder so they are both coming from the same source, ive tried adding display:none and visibility:hidden but any changes i have made affect both :(
liamb2001 replied on at Permalink Reply
or maybe you mean something else , i might be less experienced than you or tired i dont know, lol....probably both
liamb2001 replied on at Permalink Reply
so does anyone know if there is anyway of editing the script to only show on the main page then ? surely there has to be a way ???
JohntheFish replied on at Permalink Best Answer Reply
JohntheFish
This is not tested, but here is the general recipe:

Make a copy of
/concrete/blocks/search/view.php
to
/blocks/search/templates/no_results.php

Open the no_results.php file you have just created.

Delete lines 23-55 inclusive so it now reads (no changes to these lines):
<?php  defined('C5_EXECUTE') or die("Access Denied."); ?> 
<?php  if (isset($error)) { ?>
  <?php echo $error?><br/><br/>
<?php  } ?>
<form action="<?php echo $this->url( $resultTargetURL )?>" method="get" class="ccm-search-block-form">
  <?php  if( strlen($title)>0){ ?><h3><?php echo $title?></h3><?php  } ?>
  <?php  if(strlen($query)==0){ ?>
  <input name="search_paths[]" type="hidden" value="<?php echo htmlentities($baseSearchPath, ENT_COMPAT, APP_CHARSET) ?>" />
  <?php  } else if (is_array($_REQUEST['search_paths'])) { 
    foreach($_REQUEST['search_paths'] as $search_path){ ?>
      <input name="search_paths[]" type="hidden" value="<?php echo htmlentities($search_path, ENT_COMPAT, APP_CHARSET) ?>" />
  <?php   }
  } ?>
  <input name="query" type="text" value="<?php echo htmlentities($query, ENT_COMPAT, APP_CHARSET)?>" class="ccm-search-block-text" />
  <input name="submit" type="submit" value="<?php echo $buttonText?>" class="ccm-search-block-submit" />


Then, in C5, get any page with your global header in edit mode.

Click on the search block on the global header to get the menu. Select Custom Template (last option). Select 'No Results'. Save and Publish.
JohntheFish replied on at Permalink Reply
JohntheFish
PS.

Leave the search block in the main area of your search page with the regular template. Only apply the no_results template to the search block in your header.
aprobert replied on at Permalink Reply
This did it! Thank you so much for your suggestion. This seems like its been a tricky issue for others as well and I'm glad there's finally a workable solution.

I always appreciate the excellent c5 community support.
mlipenk replied on at Permalink Reply
JohntheFish,

Perfect solution! Thank you!


I understand that it is simpler to just drop one block in a blank page with both search and results. But it seems, given the fact that the majority of sites may have a search in the header, that this would be the default behavior. And there could be two default blocks... one for search one for search results.

In fact I just took the inverse of your code suggestion and made an only_results.php file that could be used for just displaying the search results.

Thanks again!
JohntheFish replied on at Permalink Reply
JohntheFish
This thread was so old I had forgotten about it. But it gives me the idea of adding the templates to the core on github or packaging them into a free addon.
rayjohn66 replied on at Permalink Reply
You are a lifesaver John, and now that I see it, it makes sense to me. I spent hours and hours thinking I did something wrong, or I was just plain stupid. Now I can move on.

Good recipe :)
JohntheFish replied on at Permalink Reply
JohntheFish
Your post drew my attention back to this (and that I had forgotten about it again).

To make up for that I have just submitted a howto based on the above post and also an addon with no_results and no_form templates.

Once approved it will be available at:

http://www.concrete5.org/marketplace/addons/search-block-templates/...
jero replied on at Permalink Reply
jero
Yes, they use the same view, but in the header you're coding the block into your template and can add extra code around it if required, and in the page area, you will have added a block to the page.