How to exclude Community posts from Guide search results?

6 Kommentare

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

    Hey Beth Borghi,

    In the latest Copenhagen version, there is a filter in the sidebar and users can use it to exclude only posts on Help Center.

     

    Hope it helps you :)

    Thanks

    0
  • Beth Borghi

    Thanks for the reply, Ifra! I'm aware of this, and trying to remind/train users to filter as well - however, since we changed to the Copenhagen theme recently, they're not in the habit yet and a bit unhappy about this. ;) Was hoping there was a way to limit it altogether - thanks!

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

    Hey Beth Borghi, use the below code for your search results template.

    <section class="container">
    {{#if results}}
      <ul class="search-results-list">
        {{#each results}}
            <li class="search-result">
              <a href="{{url}}" class="search-result-link" title="{{title}}"> {{title}} </a>
                <span class="search-result-meta-count">
                {{comment_count}}
              </span>
              {{#if vote_sum}}
              <span class="search-result-votes meta-count">{{vote_sum}}</span>
              {{/if}}
              <ul class="meta-group">
                <li>
                  <ol class="breadcrumbs search-result-breadcrumbs">
                    {{#each path_steps}}
                    <li title="{{name}}">
                      <a href="{{url}}" title="{{name}}">{{name}}</a>
                    </li>
                    {{/each}}
                  </ol>
                </li>
                <li class="meta-data">
                  {{#link 'user_profile' id=author.id}} {{author.name}} {{/link}}
                </li>
                <li class="meta-data">{{date created_at timeago=true}}</li>
              </ul>
              <div class="search-result-description">{{text}}</div>
            </li>
         {{/each}}
         {{else}}
          <p>
            {{t 'no_results' query=query}} 
          </p>
       </ul>
     {{/if}}
     {{pagination}}
    </section>
    0
  • Beth Borghi

    Hi Ifra Saqlain, thank you for the follow up! I used the above code and it limited the knowledge base articles and only showed the Community posts - I actually want it to do the opposite, and only show KB articles and no Community posts. Is that possible? Thank you!

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

    Hi Beth Borghi, 

    You can hide community post via custom JS on search results to show only KB articles.

     

    I). Add the template name to search results page.

    <script>
      templateName = "search_results";
    </script>


    Screenshot for the same:

     

    II). Now, copy and paste the below code to the your script.js file.

    $(document).ready(function() {
      if(templateName == "search_results") {
        $('.breadcrumbs.search-result-breadcrumbs li:nth-child(2) a:contains("Community")').parents(".search-result-list-item").hide();
      }
    })


    Screenshot for the same:

     

    Make sure, document_head.hbs file has jQuery Lib:

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

     

     

    Hope you will get your solution :)

    Thanks

     

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

    Update:

    • Exclude Community posts from Guide search results while searching any query.
    • But, when Community tab in Type section or select any Brand in Source section in sidebar, your search results would be default.
    $(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:

     

     

    0

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

Powered by Zendesk