You are here:  » Different searchresults.php layout depending on Product Category

Support Forum



Different searchresults.php layout depending on Product Category

Submitted by bingobongo on Fri, 2010-05-21 15:16 in

Hi there,

Thanks for your help with my previous issue!

I'm creating a mobile comparison site at the moment, with various different products - Mobile Phone Handsets (of course), Sim Only package, and Mobile Plans / Tariffs.

The existing Price Tapestry fields are fine for Handsets, but i'm adding in custom fields for the Mobile Plans/Tariffs products including 'minutes', 'minimum contract' etc.

I know I can display custom fields only if they exist in the database anywhere, but i'd like to display the results in a table format in search results, so someone searching for a tariff can compare products side by side on the searchresults.php page with the minutes, contract info visible on this page. At the same time 'regular' products like mobile phones only would look silly with empty fields for 'minutes' in their searchresults.php info.

How might this be possible? I was thinking perhaps to have a different searchresults.php based on product category?

If i'm being confusing, feel free to say and i'll explain in more detail :-)

Thanks,

Hugh

Submitted by support on Fri, 2010-05-21 15:38

Hello Hugh,

Sure - you can control which search results display file is included within search.php easily. The default version is included by the following code on line 293:

      require("html/searchresults.php");

...so if you wanted a different version for a category specific search, you could REPLACE the above code with the following (having created html/searchresultsCategory.php of course):

      switch($parts[0])
      {
      case "category":
        require("html/searchresultsCategory.php");
        break;
      default:
        require("html/searchresults.php");
        break;
      }

Hope this helps!

Cheers,
David.

Submitted by bingobongo on Fri, 2010-05-21 15:59

Excellent David,

Thanks for this - i'll give this a bash over the weekend ;-)

Submitted by bingobongo on Mon, 2010-05-24 13:56

Hi David,

Thanks so much for this!

One more question - what if I wish to show a specific searchresults.php based on a specific category? i.e. 'Pre Pay Mobile Phones'?

Thanks for your help with this :-)

Submitted by support on Tue, 2010-05-25 08:11

Sure - have a go with something like:

      switch($parts[0])
      {
      case "category":
        switch($parts[1])
        {
          case "Pre Pay Mobile Phones":
           require("html/searchresultsCategoryPrePayMobilePhones.php");
           break;
          default:
           require("html/searchresultsCategory.php");
           break;
        }
        break;
      default:
        require("html/searchresults.php");
        break;
      }

Cheers,
David.