Search within blog posts

SOLVE
Highlighted
New Contributor

I want to create sub-navigation search as it is in:

 

https://blog.hubspot.com/service

 

It should search only within blogs

Reply
0 Upvotes
2 Accepted solutions

Accepted Solutions
Regular Advisor

Hi there!

 

If you're using HubSpot's default "Site Search Input" module you should see options to specify the type of content that should be included in the search results: 

 

Site Search - Type of Content.jpg

 

You can also clone and customise the module further if you wanted it to only search a particular blog (if you have multiple). I wrote a short article on how to do this here: Add parameters to your HubSpot site search input module

 

I hope that helps!

 


Stephanie O'Gay Garcia

HubSpot CMS Design & Development

Website | Contact

 

If this helped, please mark it as the solution to your question, thanks!

Reply
0 Upvotes
Regular Advisor

You should be able to copy the code from the module and use it anywhere, so something like this should work:

 

 

<form action="/{{ site_settings.content_search_results_page_path }}">
  <label for="term">Field Label</label>
  <input type="text" class="hs-search-field__input" name="term" autocomplete="off" aria-label="Field Label | Search" placeholder="Placeholder text">
</form>

 

And you can also use the additional customisations, such as only searching on the blog:

 

<form action="/{{ site_settings.content_search_results_page_path }}">
  <label for="term">Field Label</label>
  <input type="text" class="hs-search-field__input" name="term" autocomplete="off" aria-label="Field Label | Search" placeholder="Placeholder text">
  <input type="hidden" name="type" value="BLOG_POST">
  <input type="hidden" name="type" value="LISTING_PAGE">
</form>

 

I don't believe there's a HuBL module or anything else you can use instead. 

 

 


Stephanie O'Gay Garcia

HubSpot CMS Design & Development

Website | Contact

 

If this helped, please mark it as the solution to your question, thanks!

4 Replies 4
Regular Advisor

Hi there!

 

If you're using HubSpot's default "Site Search Input" module you should see options to specify the type of content that should be included in the search results: 

 

Site Search - Type of Content.jpg

 

You can also clone and customise the module further if you wanted it to only search a particular blog (if you have multiple). I wrote a short article on how to do this here: Add parameters to your HubSpot site search input module

 

I hope that helps!

 


Stephanie O'Gay Garcia

HubSpot CMS Design & Development

Website | Contact

 

If this helped, please mark it as the solution to your question, thanks!

Reply
0 Upvotes
New Contributor

Hi there!

Thanks for your solution with default "Site Search Input" module.
But I don't want to use it and want to create this search completely by custom code.
So is there a way, I can search within hubspot blogs using custom code?

Thanks,
Parul

Reply
0 Upvotes
Regular Advisor

You should be able to copy the code from the module and use it anywhere, so something like this should work:

 

 

<form action="/{{ site_settings.content_search_results_page_path }}">
  <label for="term">Field Label</label>
  <input type="text" class="hs-search-field__input" name="term" autocomplete="off" aria-label="Field Label | Search" placeholder="Placeholder text">
</form>

 

And you can also use the additional customisations, such as only searching on the blog:

 

<form action="/{{ site_settings.content_search_results_page_path }}">
  <label for="term">Field Label</label>
  <input type="text" class="hs-search-field__input" name="term" autocomplete="off" aria-label="Field Label | Search" placeholder="Placeholder text">
  <input type="hidden" name="type" value="BLOG_POST">
  <input type="hidden" name="type" value="LISTING_PAGE">
</form>

 

I don't believe there's a HuBL module or anything else you can use instead. 

 

 


Stephanie O'Gay Garcia

HubSpot CMS Design & Development

Website | Contact

 

If this helped, please mark it as the solution to your question, thanks!

New Contributor

Thanks for reaching out Smiley Happy

We can do it this way and can also achieve it by implementing custom search using jQuery.

We can use following code to call blogs in custom module and then can implement search in it.

{% set all_posts = blog_recent_posts('default', 200) %}

{% for all_post in all_posts %}
<div class="post-title"><a href="{{all_post.absolute_url}}">{{ all_post.name }}</a></div>
{% endfor %}



Thanks

Reply
0 Upvotes