Jump to content

How to display search queries as a tag cloud on different pages

Tech Support

Recommended Posts

List of search queries is displayed by search_results block. Here is how you can put it into the main pages:

{{insert name="getBlock" block_id="search_results" block_name="Similar Searches"}}

Put it into Index and Common Videos List (renders categories, tags, models, content sources and etc.) page templates. After you add this block into page template and save, it will appear in the list of blocks on this page and you can edit its settings.

Here is template code for this block that will render cloud of search queries:

{{if count($data)>0}}
	<div class="box search-cloud">
		{{foreach item="item" from=$data}}
			{{assign var="query" value=$item.query|replace:"-":"[dash]"|replace:"&":"%26"|replace:"?":"%3F"|replace:"/":"%2F"|replace:" ":"-"|replace:"[dash]":"--"|rawurlencode}}
			<a href="{{$lang.urls.search_query|replace:"%QUERY%":$query}}" style="{{if $item.is_bold==1}}font-weight: bold; {{/if}}{{if $item.size>0}}font-size: {{$item.size}}px;{{/if}}">{{$item.query}}</a>

In block parameters configure:

  • items_per_page: the number of queries you want to be displayed.
  • sort_by: sorting of the queries.
  • var_category_dir = category
  • var_tag_dir = tag
  • size_from = 12
  • size_to = 16

Also make sure you put a cache time of 86400, as this block will be quite heavy.

When this is configured, you can see query cloud is displayed on Index and other video pages. For tag and category pages it should be relevant to the displayed tag / category. On other pages it may render the same set of queries, as they won't have context object that can be used to display similar queries.

Link to comment
Share on other sites

  • 1 month later...

Yes, possible, but only if you pass video directory in the URL. If your video URLs only have ID in them, not possible.

You can add search_results block to a video page and configure its var_query parameter to dir value:

  • var_query = dir

This should result in showing queries similar to what is in video title passed in the URL. Please make sure to put at least 86400 caching time for this block, as it will produce high load on DB and caching would be very important here.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...