Where to use it
Place this example in a PHP template at the point where you want the Better Search heatmap to appear. It outputs markup immediately. Do not paste it at the top level of functions.php or activate it as a plugin.
What to change
Set number to the number of terms to display. Adjust smallest, largest, unit, cold and hot for your theme. The sample uses all-time searches because daily is false; set it to true to use the daily_range value.
The function_exists() check prevents the call when the heatmap function is unavailable. It does not guarantee that search data exists.
Requirements
- Better Search
- Better Search must be active.
- Use a PHP theme template after WordPress and the plugin have loaded.
Source
better-search/bsearch-heatmap-example.php<?php
/**
* This is an example to display the Better Search Heatmap
* by changing the default parameters.
*
* @package Better_Search
*/
if ( function_exists( 'get_bsearch_heatmap' ) ) {
// All these parameters are optional. If you don't pass any of these, the plugin will default to the options set in the Better Search settings page.
$args = array(
'daily' => false,
'smallest' => '10', // Heatmap - Smallest Font Size.
'largest' => '20', // Heatmap - Largest Font Size.
'unit' => 'pt', // Heatmap - We'll use pt for font size.
'cold' => 'ccc', // Heatmap - cold searches.
'hot' => '000', // Heatmap - hot searches.
'before_term' => '', // Heatmap - Display before each search term.
'after_term' => ' ', // Heatmap - Display after each search term.
'number' => '30', // Heatmap - Maximum number of searches to display in heatmap.
'daily_range' => '7', // Daily Popular will contain posts of how many days?
);
echo get_bsearch_heatmap( $args ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}Details
- Type
- Template example
- Last updated
- GitHub
- Source · Edit companion · History