searchpromotions.rst 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. .. _editors-picks:
  2. =======================
  3. Promoted search results
  4. =======================
  5. .. module:: wagtail.contrib.search_promotions
  6. The ``searchpromotions`` module provides the models and user interface for managing "Promoted search results" and displaying them in a search results page.
  7. "Promoted search results" allow editors to explicitly link relevant content to search terms, so results pages can contain curated content in addition to results from the search engine.
  8. Installation
  9. ============
  10. The ``searchpromotions`` module is not enabled by default. To install it, add ``wagtail.contrib.search_promotions`` to ``INSTALLED_APPS`` in your project's Django settings file.
  11. .. code-block:: python
  12. INSTALLED_APPS = [
  13. ...
  14. 'wagtail.contrib.search_promotions',
  15. ]
  16. This app contains migrations so make sure you run the ``migrate`` django-admin command after installing.
  17. Usage
  18. =====
  19. Once installed, a new menu item called "Promoted search results" should appear in the "Settings" menu. This is where you can assign pages to popular search terms.
  20. Displaying on a search results page
  21. -----------------------------------
  22. To retrieve a list of promoted search results for a particular search query, you can use the ``{% get_search_promotions %}`` template tag from the ``wagtailsearchpromotions_tags`` templatetag library:
  23. .. code-block:: html+django
  24. {% load wagtailcore_tags wagtailsearchpromotions_tags %}
  25. ...
  26. {% get_search_promotions search_query as search_promotions %}
  27. <ul>
  28. {% for search_promotion in search_promotions %}
  29. <li>
  30. <a href="{% pageurl search_promotion.page %}">
  31. <h2>{{ search_promotion.page.title }}</h2>
  32. <p>{{ search_promotion.description }}</p>
  33. </a>
  34. </li>
  35. {% endfor %}
  36. </ul>