CMS Development

jwiedenheft
Contributor

Custom Site Search - Need to Include Landing Pages in Results

SOLVE

Website here -> www.greatamerica.com

Issue -> Include Landing Pages in custom search function

 

On our website, there's a custom search icon/module in the top navigation bar. I'm trying to get this search function to include Landing Pages in the Search Results. The search function is built into the code of the Header Module, so none of the Site Search documentation is helping me.

 

Any assistance would be helpful!

 

Here's the hopefully relevant part of the module.html

<div class="grid__item portable-two-twelfths hard--ends lap-and-up-visuallyhidden">
        <div class="header--searchmobile--trigger">
        </div>
      </div>
      <div class="grid__item nine-twelfths portable-visuallyhidden hard text--left">
        <div class="grid short hard">
          <div class="grid__item one-whole hard--ends text--right">
            <div class="header--search">
              <form class="header--search--body">
                <input class="header--search--input" placeholder="{{ module.search_placeholder_text }}">
              </form>
              <span class="header--search--trigger"></span>
            </div>
            <script>
              function headerSearchSubmit() {
                if ($("body").find(".header--search").hasClass("active")) {
                  if ($("body").find(".header--search--input").val()) {
                    if ($("body").find(".header--search--input").val().trim().length > 0) {
                      window.location.href = "{{ module.search_url_of_search_results_page.href }}?term="+$("body").find(".header--search--input").val().trim();
                    }
                    }
                    }
                      else {
                      $("body").find(".header--search").addClass("active");
                    }
              }
              $("body").find(".header--search .header--search--trigger").click(function (e) {
                e.preventDefault();
                headerSearchSubmit();
              });
                      $("body").find(".header--search .header--search--body").submit(function (e) {
                      e.preventDefault();
                      headerSearchSubmit();
                    });
            </script>

 

 

0 Upvotes
1 Accepted solution
jwiedenheft
Solution
Contributor

Custom Site Search - Need to Include Landing Pages in Results

SOLVE

Might have just figured this out.

 

I added "type=LANDING_PAGE" to the URL part of the function.

 

window.location.href = "{{ module.search_url_of_search_results_page.href }}?type=LANDING_PAGE&term="+$("body").find(".header--search--input").val().trim();

View solution in original post

4 Replies 4
jwiedenheft
Contributor

Custom Site Search - Need to Include Landing Pages in Results

SOLVE

Solution was based on the code I found on this Site Search post from 2018:

 

https://www.bluleadz.com/blog/3-reasons-why-site-search-is-important-and-how-to-implement-search-in-...

0 Upvotes
piersg
Key Advisor

Custom Site Search - Need to Include Landing Pages in Results

SOLVE

Hubspot also has a search API you can use, includes SITE_PAGELANDING_PAGEBLOG_POSTLISTING_PAGE, and KNOWLEDGE_ARTICLE.

 

Documentation here: https://legacydocs.hubspot.com/docs/methods/content/search-for-content

jwiedenheft
Contributor

Custom Site Search - Need to Include Landing Pages in Results

SOLVE

Yes! Thank you! I knew those were the options I needed to add, I just didn't know where to add them since this wasn't a module itself, but a function/script written within a custom module.

0 Upvotes
jwiedenheft
Solution
Contributor

Custom Site Search - Need to Include Landing Pages in Results

SOLVE

Might have just figured this out.

 

I added "type=LANDING_PAGE" to the URL part of the function.

 

window.location.href = "{{ module.search_url_of_search_results_page.href }}?type=LANDING_PAGE&term="+$("body").find(".header--search--input").val().trim();