I set up a view in drupal 7 that displays all my content. I exposed filter criteria's Title and Taxonomy, so now there's a title and taxonomy search field that appears above the result set. How do I print custom text like "Search Results:" between the filters and the results?
This can easily be achieved using themeing.
- In the edit view for your view click on advanced
- At the bottom of the section is "theme information"
- Look for the line "Display output" and from left to right the themeing becomes more specific
- Decide how specific you want the themeing to be (hint if unsure go to the right)
- Copy the theme file name (which should be something like
views-view--example--page.tpl.php) and create a new file in your theme folder with that name
- Click on the display options link and copy the contents of the file from the
<?phpthrough to the bottom of the fixed width text and paste that into the new file
- Add your text after the code block that looks like this:
<?php if ($exposed): ?>
<?php print $exposed; ?>
<?php endif; ?>
- Save the file
- Click the "Back to theming information" link
- Click the rescan template files link
- Save your view
- Visit the page your view is on
Quick edit to the previously provided response:
Copy the views-view.tpl.php provided by the Views module into your templates folder of your theme, and rename it views-view--example--page.tpl.php
<?php if ($exposed): ?> <div class="view-filters"> <?php print $exposed; ?> </div> <?php endif; ?>
<?php if (!$empty): ?> <?php print t('Your search results are below.'); ?> <?php endif; ?>
Save the file. Make sure to rescan you template files within the view.
This ensures that your custom text is only displayed when results are found. Without the check to see if the view is empty, your custom text will display even if no results are found, which is not good UX.