After setting up your menu structure you might run into this paradox.
What happens when you search your site using the K2 Tools module?
The answer is the search results are displayed in your current menu item. This is quite all right when you use a common layout for your inner pages and your frontpage.
On the other hand, if your site has a complex layout. Let’s say a slideshow or multiple content modules and the list goes on you might want to simplify the search results page.
The solution would be to create a menu item for these listings so you can control your modules. Guess what.. it is easier than you think, just follow these simple steps.
Step 1: Create a new menu item
You first need to create a menu item for the results. For maintenance reasons and the sake of clarity I always create a search form or results menu item.
Hint: Leave the Search Term field empty.
Step 2: Copy its id
In this step you need to copy the menu item’s id. You can easily find its id since it is the last parameter in the URL. The image bellow will explain it a lot better if you are still confused.
Example: For a URL like site.com/administrator/index.php?option=com_menus&view=item&layout=edit&id=190 the id would be 190.
Step 3: The overriding part
If your template already has overrides for the K2 tools modules you can safely ignore this part.
If you read the K2 inheritance & sub-templating post by Yiota, you already know how easy it is to locate the files to override.
For those of you who didn’t read that post, this piece of documentation is quite helpful as well as Yiota’s post.
The K2 Tools module files are located in the /modules/mod_k2_tools/ folder and the file you need to override is search.php which is located inside the /modules/mod_k2_tools/tmpl/ folder.
Follow the same procedure which is described in these two posts and move this file in your template’s html/mod_k2_tools/ folder. Your final file structure should match the one in the following image.
Step 4: Now the coding (and final) part
As you might have already suspected, what we need to do is to make the form's action post in that particular menu item.
To achieve this you need to edit the form’s action attribute and append the menu item id you copied in step 2.
Is this all Greek to you? No worries just use the following snippet.
You need to change this line of code
<form action="<?php echo $action; ?>" method="get" autocomplete="off" class="k2SearchBlockForm">
<form action="<?php echo JRoute::_('index.php?option=com_k2&view=itemlist&task=search&Itemid=THE_MENU_ITEM_ID'); ?>" method="get" autocomplete="off" class="k2SearchBlockForm">
Voila! Now you have a menu item just for your search results. The final thing you might need to do it to publish some modules specifically for this menu item to spice it up a bit but this is completely optional. If are already experienced with PHP you can always tamper with the $action variable.
Using this method will not only give you the utmost control over your layout. It will also and most importanly help you with a critical element, consitency in your layout.