JoomlaWorks

Member Dashboard
  • Home
  • Extensions
    • Commercial
      • Frontpage Slideshow
      • K2 Plugin for sh404SEF
      • Simple Image Gallery Pro
      • SocialConnect
    • Free
      • K2
      • AllVideos
      • DISQUS Comments for Joomla!
      • IAKI (Import As K2 Image)
      • Quick Menu (for Joomla 4)
      • Simple Image Gallery
      • Simple RSS Feed Reader
    • Free On Github
      • Akismet for Kunena
      • Fill It Up
      • K2 Example Plugin
      • K2 Links for JCE
      • Rebuild K2 Image Cache (CLI utility for K2)
      • TinyLetter Subscribe
      • URL Normalizer
      • User Extended Fields for K2
  • Templates
    • Commercial Templates
      • Anagram
      • Archetype
      • BusinessOne
      • Ibento
      • Janaro
      • Kiji
      • Matchbox
      • nuMuzik
      • RadioWave
      • Toreda
    • Free Templates
      • nuModusVersus
      • Takai
  • Demos
    • Joomla Extension Demos
    • Joomla Template Demos
    • WordPress Plugin Demos
  • Labs
    • Web Apps
      • JSON 2 JSONP
      • Feed Reader (bookmarklet)
      • Device Info
  • Support
    • Documentation for Joomla Extensions
      • AllVideos
      • Frontpage Slideshow
      • Simple Image Gallery
      • Simple Image Gallery Pro
      • SocialConnect
    • Documentation for Joomla Templates
      • General Resources
        • Installation
        • Content
        • Customization
      • Commercial Templates
      • Free Templates
    • Get Help
      • Community Forum
        • Recent Topics
        • Categories
        • Create free account
      • Help Desk
      • Contact us by e-mail
      • Contact us on Facebook Messenger
      • Contact us on Twitter
  • About
    • Blog
    • Company
    • License & Terms of Service
    • Privacy Policy
  • My Account
09 05 2014
Written by  JoomlaWorks
Published in Blog
Tagged under
  • +enhancement
  • +development
4 comments

Enhancing your K2 Site (Part 1): Better search results

Enhancing your K2 Site (Part 1): Better search results

A common pitfall you might have run into is publishing or hiding modules in views that do not use a specific menu item. In this blog post we are shedding some light into K2 search results and how to extend their functionality. We will assign a menu item to the K2 search results so we can have even more control over our modules.

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.

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.

menu-id

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.

folder-strucutre

 

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">

to:

<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.

 

Final Note

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.

 

Read 38765 times Last modified on Wednesday, 28 January 2015 18:22

4 comments

  • Alex Jackson Alex Jackson 22 May 2016
    Comment Link

    OK great, now how can we get the search to pull tags from other 3rd party extensions. Specifically Music collection for joomla. It seems that no search modules pick up on its data? Maybe I am overlooking something.

  • Ben-Donner Ben-Donner 29 Jan 2016
    Comment Link

    Thank you for this good article! I am not completely sure if I can get the results that I want with this method though? :

    I need the K2 Search results to be displayed with the same layout as I use when showing a items in a K2 category (menu item type K2 -> Categories). This layout is taken from the ../templates/templ_name/html/com_k2/templates/category_item.php file and ../templates/templ_name/css/k2.css files. Any way to use the layout from these? It is not a very easy job it seems to change the search.php file to parse as the category_item.php does.

    Thanks,
    Ben

  • Matt Matt 29 Oct 2015
    Comment Link

    We've implemented this code yet the search page is still showing as the generic k2 search results page. Is there something else that must be done? We have created the menu item and edited the search.php files in both the overrides and in the core files.

  • AlexeyP AlexeyP 18 Jun 2015
    Comment Link

    That works fine. But anyhow I'm getting the problem with URL of search results page which looks like:
    /component/k2/search?searchword=test&limit=5&start=5
    How can I avoid it in easiest way?
    Seo options in joomla are on.

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.

back to top
BY MAIL BY RSS

Archives

  • March 2023 (1)
  • January 2022 (1)
  • July 2021 (2)
  • May 2021 (1)
  • February 2021 (1)
  • December 2020 (1)
  • September 2020 (1)
  • June 2020 (1)
  • May 2020 (1)
  • February 2020 (1)
  • January 2020 (5)
  • December 2019 (2)

Tag Cloud

allvideos announcement apache community development frontpage slideshow joomla k2 Performance plugin release sh404sef simple image gallery simple image gallery pro simple rss feed reader socialconnect ssh tips update video

Latest Entries

  • New free extension release: Quick Menu (for Joomla 4)
    Written by  JoomlaWorks
    06 Mar 2023
  • Simple Image Gallery (free) v4.2 released
    Written by  JoomlaWorks
    07 Jan 2022
  • Simple Image Gallery Pro v3.9.1 released (bug-fix release)
    Written by  JoomlaWorks
    26 Jul 2021
  • Simple Image Gallery Pro v3.9.0 released
    Written by  JoomlaWorks
    05 Jul 2021
  • Simple RSS Feed Reader v3.9.0 released
    Written by  JoomlaWorks
    25 May 2021

Join Our Newsletter

Enter your e-mail address to subscribe to our new or updated product notifications. We send combined newsletters, so we won't spam you every week :)

Get Social

  • Twitter
  • GitHub
  • Facebook
  • GitHub (K2)
  • YouTube
  • Speaker Deck

Grab Our Feeds

  • Extension Updates
  • Blog
  • Videos
  • Presentations
Copyright © 2006 - 2023 JoomlaWorks Ltd.
JoomlaWorks Ltd. and this site is not affiliated with or endorsed by The Joomla! Project™. Any products and services provided through this site are not supported or warrantied by The Joomla! Project or Open Source Matters, Inc. Use of the Joomla!® name, symbol, logo and related trademarks is permitted under a limited license granted by Open Source Matters, Inc.
designed by Nuevvo