Search Results appearing twice on Search Page
Permalink
I am in the process of building a C5 site and have coded the search block into my header.php, so it is part of my theme and I have setup a search-results page that it sends its results to... so far so good, all is working as planed.
However I have an issue where the results on the search results page are shown both on the header search block AND on the search block that is on the content portion of the page. In the attached image the area I do not want is circled in the upper right.
So I am looking for a way to test from the view.php of the search block to see if I am in the content area before I show the results or some other way to make sure I only show the results in the content area and not the header.
Thanks for your ideas!
However I have an issue where the results on the search results page are shown both on the header search block AND on the search block that is on the content portion of the page. In the attached image the area I do not want is circled in the upper right.
So I am looking for a way to test from the view.php of the search block to see if I am in the content area before I show the results or some other way to make sure I only show the results in the content area and not the header.
Thanks for your ideas!
Here is the image I referred to in the previous post.
A little while after I posted I figured out my answer. In the template I called for the search block in the header (a copy of the view.php from the search block), I removed the code for displaying the results and it works as I wanted it to. I query on the top and get results on the bottom.
It seems that you're the only person who had this problem and solved it.Can you please once again describe the solution in details?
What code have you deleted and where?
Thanks.
What code have you deleted and where?
Thanks.
In the header template of my theme I hardcoded a search block with the following:
Then in my theme's block directory, under the search block directory I created a directory called templates. In the templates directory I created a file called search_header.php. In that file I copied the first 21 lines from the base concrete5 search block and then modified them so my input looked how I wanted it. Attached is my search_header.php
Then I copied the base search block to the blocks directory the root of C5 install. I then updated the view.php to remove the search field to just have the results and not the search input. My view.php is also attached.
Hopefully this helps make what I did clearer.
<div id="search-logo-top"> <?php $bt = BlockType::getByHandle('search'); $bt->controller->title = ''; $bt->controller->buttonText = ''; $bt->controller->baseSearchPath = ''; $bt->controller->resultsURL = '/search-results'; $bt->render('templates/search_header'); ?> </div>
Then in my theme's block directory, under the search block directory I created a directory called templates. In the templates directory I created a file called search_header.php. In that file I copied the first 21 lines from the base concrete5 search block and then modified them so my input looked how I wanted it. Attached is my search_header.php
Then I copied the base search block to the blocks directory the root of C5 install. I then updated the view.php to remove the search field to just have the results and not the search input. My view.php is also attached.
Hopefully this helps make what I did clearer.
Thanks for posting this link. It looks to me that we followed a similar process with the difference of my project wanting a hard coded search block and your approach allowing more flexibility.
I did this a number of years ago and there wasn't a guide like yours around. It should make it a lot easier for the next group of people trying to figure this out.
I did this a number of years ago and there wasn't a guide like yours around. It should make it a lot easier for the next group of people trying to figure this out.