Default search to show articles only
I need to be able to change the default setting in Guide search so that it shows articles only, rather than articles and community posts. I don't want to hide community comments completely, just change the default results. Is there a way to get this so that users can still select to include community posts using the left-hand menu?
This is the same a Jeff S' question here. Support also mentioned it may need coding, so any help with what I'd need to add would be greatly appreciated!
-
Hi Gwyn,
It does require a bit of custom JS code. You'll want to take a look at the Help Center templating cookbook to get familiar with how to edit code within your Guide theme. This post also shows a bit of a demonstration on one way to achieve it.
Hope this helps!
Erica
-
Hi Gwyn Mabo :)
Copy and paste the given JS code to your script.js file:
- It shows articles only, rather than articles and community posts.
- Users can still select to include community posts using the left-hand menu.
$(document).ready(function() {
if(templateName == "search_results") {
if (window.location.href.indexOf("community") < 1) {
if (window.location.href.indexOf("source") < 1) {
$('.breadcrumbs.search-result-breadcrumbs li:nth-child(2) a:contains("Community")').parents(".search-result-list-item").hide();
}
}
}
})
Screenshot:
Complete Guide: https://support.zendesk.com/hc/en-us/community/posts/4589496379162-How-to-exclude-Community-posts-from-Guide-search-results-Thanks
-
Thank you so much, Ifra! Which line would I paste this code into or does it not matter too much?
-
Just copy the script code and paste it at bottom area to script.js file.
Screenshot:
Add template name to the search results file:
Copy the jquery CDN and paste it to the document_head.hbs file.
jquery CDN:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
Screenshot: -
Thanks Ifra! Appreciate you sharing your solution. 😊️
-
😊️
-
Hi Ifra, I've applied the code as instructed, but it hasn't changed the search results format at all. Is there anything else I've missed?
-
@Gwyn Mabo, it's working for me, may be classes are different or something else. Can you share your URL of your HC?
-
Hi Ifra, I haven't edited the code on my live site, but a draft theme.
-
If you didn't add the code in your live site then how can you get any kind of output for live as you want?
You added in your draft theme then you can see the output in your draft theme search results page not in your live site.
-
Hi Ifra, I wasn't using the live site to test it, I was using the preview version of the draft theme. I assumed (like it does with other changes viewed using the preview) that this would work.
-
Hi Gwyn Mabo,
Test like this:-
Search "What" in the search-bar.
Only articles would be list with what string not community posts.
But when you remove the added code (Given above) from script file then all posts would be shown (If exist with the 'what' string) as default results on the page.
-
Hi Ifra, that is exactly what I did, and it did not work I'm afraid.
-
Hi Gwyn :), is there any way I can see the bug in your theme?, then I can provide some solution.
-
Hi Ifra, more than happy for you to help out, what do I need to do?
-
You should set your draft mode theme live, then share the URL here.
Please sign in to leave a comment.
16 Comments