Restricting search results

Beantwortet

27 Kommentare

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

    Hi Louise Moghaddam, :)

     

    you can try this, check article and then hide that from search results page:

    $(".results-list-item-link:contains(What are these sections and articles doing here?)").parent().parent().hide();

    $(".results-list-item-link:contains(What are sections?)").parent().parent().hide();

    $(".results-list-item-link:contains(What are categories?)").parent().parent().hide();

     

    Thanks

    0
  • Louise Moghaddam

    Thanks Ifra, sorry, I don't understand what you mean. Could you outline the exact steps please? Many thanks!

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

    Loiuse, the given code is 

    $(".results-list-item-link:contains(What are these sections and articles doing here?)").parent().parent().hide();

     

    This is my article title in the code which I want to hide on search results page:

    What are these sections and articles doing here?

     

     

    So, you only need to remove my article title and add your article title one by one in the code. I'm doing this for my three articles only.

    $(".results-list-item-link:contains(What are these sections and articles doing here?)").parent().parent().hide();

    $(".results-list-item-link:contains(What are sections?)").parent().parent().hide();

    $(".results-list-item-link:contains(What are categories?)").parent().parent().hide();

     

    1). What are these sections and articles doing here?

    2). What are sections?

    3). What are categories?

     

     

     

    you just add the given code to the scritp.js file and replace my article's title with yours which you wanna exclude.

    0
  • Louise Moghaddam

    It's worked! Thank you for helping Ifra, apologis for being such a luddite!!

    0
  • Bob Rosenbaum

    Hi Ifra Saqlain.

    Could the approach described above be adapted for the hiding search results from an entire Category? We have several specific Categories that we want to effectively 'exclude' from all searches.

    Thanks for any tips you can provide.

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

    Hi Bob Rosenbaum,

     

    Please see the solutions.

    Solution 1:

    If you want so then you can set your category 'save as draft' mode then only admin can show that specific category.

     

    Solution 2:

    Use this code and replace the category name 'General'. This code will hide the complete Category from search result sidebar and hide articles on the search page.

    $(".sidenav-subitem.filter-name:contains(General)").parent().parent().hide();

    var _x = $(".breadcrumbs > li > a:contains(General)").parentsUntil(".search-result-meta-container").parent().parentsUntil("article").parent();
    $(_x).parent().hide();

     

    Hope it is worked for you I just tried.

    Thanks :)

     

    0
  • Bob Rosenbaum

    Thanks very much Ifra Saqlain!
    Yes, we already use the Draft attribute for some categories, but for others it looks like your code can work well. I am tweaking it slightly to fit the requirements of our Search Results page, as it is a bit different from the Copenhagen theme.
    My thanks again for your quick assistance here.

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

    Any time Bob Rosenbaum :)

    If there is any issue let me know and you can share URL of your woring theme as well then I can find exact solution for you.

    0
  • Tobias Grønbæk Melander

    Hi Ifra Saqlain,

    I tried pasting the code above into my script.js and changing the article title, but couldn't get it to work.

    It looks like this when put into my Help Center:

    $(".results-list-item-link:contains(Approvals)").parent().parent().hide();

    Can you assist me?

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

    @Tobias Grønbæk Melander, this code isn't for changing article title.

    First you tell me the page name where you want to change article title and tell your current article title then I'll provide the exact solution here.

     

     

    0
  • Tobias Grønbæk Melander

    Ifra Saqlain

    What I meant is I that I changed the article title from yours to mine, so as to hide the given article from the search results using the solution you provided earlier in this thread.
    When trying to use that solution however, it doesn't work. I have also had success in hiding the article from the category and section pages using the 'isnt helper' like Louise.

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

    Tobias Grønbæk Melander,

     

    Use the below code to hide article from search results page, replace my article title (What is the article?) to yours:

     $(".search-result-title a:contains(What is the article?)").parentsUntil("ul").hide();

     

    I'll work and if not let me know:)

    0
  • Tobias Grønbæk Melander

    Hi Ifra Saqlain,

    Thanks for returning to me so quickly! :)

    I tried the code, but unfortunately it doesn't seem to work either:

    Did I put the code somewhere wrong?

    Thanks again.

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

    Steps to follow:

    i). Add JQuery CDN to your document_head.hbs file.

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


    Screenshot for the same:

     

     

    ii). Add wrap this code inside a function like below:

    $(document).ready(function(){
      $(".search-result-title a:contains(Approvals)").parentsUntil("ul").hide();
    });


    Screenshot for the same:
    0
  • Tobias Grønbæk Melander

    Ifra Saqlain

    Thanks for the help, but unfortunately it didn't work:

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

    Check your console on preview mode, is there any error?

    OR

    You can share URL of your theme here then I can figure out the bug and after fixing the bug, you can remove URL by editing your comment.

     

    0
  • Tobias Grønbæk Melander

    There seems to be one yes:

     

    I've mostly been working in a test environment, so as not to break anything in the live version. Can I still share that? Or is it the link to the theme we're using? (Flatrock from Lotusthemes).

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

    Tobias Grønbæk Melander , remove the previous code and use this code, it will definitely work, I have tested and updated yet using Flatrock theme, actually, classes are different that's why the previous code isn't working for you.

    $(document).ready(function(){
    $(".lt-search-result__title a:contains(Approvals)").parentsUntil("ul").hide();
    });
    0
  • Tobias Grønbæk Melander

    Ifra Saqlain,

    Thank you, that helped! 

    (However only for the newest version of Flatrock it seems, but that's no issue, just noticed it didn't work in one of my test environments).

    0
  • Ashley Moore

    Ifra Saqlain

    We are having the same issue when trying to hide this term:

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

    Ash,

    What's your theme name? because there may be different class names. you can try this class:

    $(document).ready(function(){
      $(".search-result-title a:contains(Approvals)").parentsUntil("ul").hide();
    });


    Note: Remove Approvals from JS code, write your article title here, then test.

     

     

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

    Tobias Grønbæk Melander, I'm glad that it worked you!

    0
  • Ashley Moore

    Ifra Saqlain

    Theme: Flatrock + Alerts - v2

    Tried with you suggestion but it didn't work. :(

    1
  • Michael Buckley

    Ifra Saqlain Hi! Any thoughts on Ashley Moore's post? We're still stuck on this

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

    Michael Buckley

    this is my code snippet

    $(document).ready(function(){
      $(".search-result-title a:contains(Approvals)").parentsUntil("ul").hide();
    });

     

    If it's not working then definitely the class name is different in your theme.

    Change this class-name -- search-result-title, in the code, it will definitely work.

    i). Go to your search_results_page.hbs file.

    ii). Find for search-results-list.

    iii). You can see <h2> tag under the list. There is a class, copy that and paste it into the given script code.

     

    In Copenhagen theme, <h2> tag has this class-name so I have added this class-name in my code.

     

    You will have different so remove my class-name and add yours.

     

    Thanks

     

    0
  • Ogaki

    Hi! Ifra Saqlain,

    Your code worked on the native search result but the article still shows on "Instant search" result. Is there any way to hide them from Instant search as well?

    0
  • Dganit Rauchwerger

    Hi Ifra Saqlain,

    I have an article that I want to make unsearchable in the Help Center. People will only be able to access the article with a direct link. I saw previous posts where you provided guidelines on how to implement this.

    1. Please confirm that I need to add the code to the script.js file.
    2. What is the exact code that I need to add and in what line?

    Thank you so much,

    Dganit

    0

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

Powered by Zendesk