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...
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...
I'm doing this in my 5.4.2.2 template:
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 ;)
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 ;)
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, 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 ??
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 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?
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?
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 :(
or maybe you mean something else , i might be less experienced than you or tired i dont know, lol....probably both
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 ???
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):
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.
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" />
Viewing 15 lines of 16 lines. View entire code block.
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.
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.
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.
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.
I always appreciate the excellent c5 community support.
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!
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!
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.
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 :)
Good recipe :)
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/...
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/...
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.
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...