Restricting search results
回答済みI want to hide certain articles from my help centre and make them only accessible via a link. I've hidden them from the homepage and the articles lists in sections using the 'isnt helper' but I can't see how to exclude them from search results. Is there a way to do this?
-
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
-
Thanks Ifra, sorry, I don't understand what you mean. Could you outline the exact steps please? Many thanks!
-
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.
-
It's worked! Thank you for helping Ifra, apologis for being such a luddite!!
-
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.
-
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 :)
-
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. -
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.
-
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?
-
@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.
-
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. -
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:)
-
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. -
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: -
Thanks for the help, but unfortunately it didn't work:
-
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.
-
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).
-
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();
}); -
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).
-
Ifra Saqlain
We are having the same issue when trying to hide this term: -
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. -
Tobias Grønbæk Melander, I'm glad that it worked you!
-
Ifra Saqlain
Theme: Flatrock + Alerts - v2
Tried with you suggestion but it didn't work. :(
サインインしてコメントを残してください。
23 コメント