©2006-2017 IAAI Software

Contact Us Privacy Policy

Multiple templates for seach shortcode

Submitted by uck on Sat, 2017-06-17 16:45.

Hi David,

I'm currently using the shortcode [pto search="Keywords"] in my WP web site and, if possible, I would like to create multiple templates it to use in different parts of the site.


[pto1 search="Keywords"] -> to show titles without images and descriptions
[pto1 search="Keywords"] -> to show images without tiles and descriptions,

Is that possible with just minor modifications? If so, could you provide some general direction to get it done?

Thank you

Submitted by support on Mon, 2017-06-19 10:53.


Sure - what you could do is add support for multiple templates to be defined within the Search Results / Each template, using %name%....%name% delimiters, including a %default%...%default% section for normal search results / related products, for example:

  <!-- existing search results / each template HTML here -->
  <!-- alternative HTML for template1 here -->
  <!-- alternative HTML for template2 here -->

With that in place, edit pto.php and look for the following code at line 826:

          $html .= pto_search();

...and REPLACE with:

          global $pto_searchTemplate;
          if (isset($atts["template"])) $pto_searchTemplate = $atts["template"];
          $html .= pto_search();

And finally edit pto_search.php and look for the following code beginning at line 533:

  $html = "";

...and REPLACE with:

  global $pto_searchTemplate;
  if (!isset($pto_searchTemplate)) $pto_searchTemplate = "default";
  $pto_html_search_each = str_replace(array("\n","\r")," ",$pto_html_search_each);
  $pto_html_search_each = $matches[1];
  $html = "";

And then use shortcodes for example;

[pto search="Keywords" template="template1"]

[pto search="Keywords" template="template2"]

Hope this helps!