Default search to show articles only

16 Kommentare

  • Erica Girges
    Zendesk Developer Advocacy
    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
    0
  • Ifra Saqlain
    Community Moderator
    Most Engaged Community Member of The Year - 2021

    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

    Team

     

    0
  • Gwyn Mabo

    Thank you so much, Ifra! Which line would I paste this code into or does it not matter too much?

    0
  • Ifra Saqlain
    Community Moderator
    Most Engaged Community Member of The Year - 2021

    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:


    0
  • Erica Girges
    Zendesk Developer Advocacy
    Thanks Ifra! Appreciate you sharing your solution. 😊️
    0
  • Ifra Saqlain
    Community Moderator
    Most Engaged Community Member of The Year - 2021

     😊️

    0
  • Gwyn Mabo

    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?

    0
  • Ifra Saqlain
    Community Moderator
    Most Engaged Community Member of The Year - 2021

    @Gwyn Mabo, it's working for me, may be classes are different or something else. Can you share your URL of your HC?

    0
  • Gwyn Mabo

    Hi Ifra, I haven't edited the code on my live site, but a draft theme.

    0
  • Ifra Saqlain
    Community Moderator
    Most Engaged Community Member of The Year - 2021

    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.

     

    0
  • Gwyn Mabo

    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.

    0
  • Ifra Saqlain
    Community Moderator
    Most Engaged Community Member of The Year - 2021

    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.

    0
  • Gwyn Mabo

    Hi Ifra, that is exactly what I did, and it did not work I'm afraid.

    0
  • Ifra Saqlain
    Community Moderator
    Most Engaged Community Member of The Year - 2021

    Hi Gwyn :),  is there any way I can see the bug in your theme?, then I can provide some solution.

    0
  • Gwyn Mabo

    Hi Ifra, more than happy for you to help out, what do I need to do?

    0
  • Ifra Saqlain
    Community Moderator
    Most Engaged Community Member of The Year - 2021

    You should set your draft mode theme live, then share the URL here.

    0

Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.

Powered by Zendesk