-
AuthorPosts
-
January 18, 2020 at 12:11 pm #1175800
Hi,
I’m using plugin Knowledge Base (Echo plugins) in which I have added a lot of documents (mostly PDF’s, but also external links). They are all set to open in a new window. This is working fine except for when they are appearing in a search result. All search results are opening in the same window. For pages on the website this is fine, but I want the external links and links to PDF’s to open in a new window.
I’m using plugin Relevanssi for better search results. I have asked the same question on that forum but Mikko Saari (from Relevanssi) referred me to Enfold support stating that I have to modify my search results template.
Can you help me with that?
Thanks a lot!
January 19, 2020 at 7:25 pm #1176065Hey JantienM,
Can you please give us the link to the page with the issue?
Best regards,
VictoriaJanuary 21, 2020 at 10:28 am #1176636It’s the search result page. You can enter a search word in the search field on the website (eg kindermishandeling), you get this: https://www.toolkitaandachtsfunctionaris.nl/nieuw2019/?s=kindermishandeling
All results are opening in the same window, I want ALL PDF’s and external links to open in a new window. Eg the first search result is an external link to a website (Website – Stuk “Wat is kindermishandeling”). It opens in the same window. I want it to open in a new window.
You can see, when you go to the Knowlegde Base (https://www.toolkitaandachtsfunctionaris.nl/nieuw2019/kennisbank/) and look for the same link at the bottom of the category “Kindermishandeling” (Website – Stuk “Wat is kindermishandeling”), it opens in a new window, which is correct.
So I guess the PHP search template needs to be modified.
- This reply was modified 4 years, 11 months ago by JantienM.
January 22, 2020 at 8:00 pm #1177262Hi JantienM,
Yes, you need to modify the /enfold/search.php file to have all the external links to open in the new tab. Or maybe it can be easier done with the JavaScript, just to find the links with the pdfs and add the appropriate attribute.
Best regards,
VictoriaJanuary 23, 2020 at 10:07 am #1177495Thanks Victoria,
I was actually hoping you could help me with that, because my knowledge doesn’t go that far.
I was expecting it would be working, because I allready have set all the documents and external links to open in a new window.
Hope you can help me with a code to put in de PHP search template or otherwise.
Thanks a lot!
January 24, 2020 at 4:55 am #1177978Hi,
Thank you for following up.
As @Victoria suggested, try to modify the includes > loop-search.php file, look for this code around line 52..
echo "<{$heading} class='post-title entry-title {$css}'><a title='".the_title_attribute('echo=0')."' href='".get_permalink()."' $markup>".get_the_title()."</a></{$heading}>";
.. and add the target attribute to the link tag.
echo "<{$heading} class='post-title entry-title {$css}'><a target='_blank' title='".the_title_attribute('echo=0')."' href='".get_permalink()."' $markup>".get_the_title()."</a></{$heading}>";
Best regards,
IsmaelJanuary 24, 2020 at 12:52 pm #1178100Thanks Ismael!
This is working, but now the links in the search results that link to a page are also opening in a new window. Is there a way to fix this?
Thanks again!
January 27, 2020 at 4:19 am #1178557Hi,
Thank you for the update.
How exactly did you add the external links and pdf files?
Try to replace the line with this code.
$blank = in_array(get_post_type($the_id), array('page', 'post', 'product')) ? '' : 'target="_blank"'; echo "<{$heading} class='post-title entry-title {$css}'><a {$blank} 'title='".the_title_attribute('echo=0')."' href='".get_permalink()."' $markup>".get_the_title()."</a></{$heading}>";
Best regards,
IsmaelJanuary 27, 2020 at 3:40 pm #1178722Hi Ismael,
I changed the code line and it works like a charm!
I added the external and PDF links with Echo plugin Knowledge Base.
One quesion, I changed the code in the core file (loop-search.php) now, I’d rather change it in a child file. How can I do that? Do I make a copy of the whole file and place it in my Enfold-child folder (in a subfolder includes)? Or can I copy only this code into a PHP file?
<?php $blank = in_array(get_post_type($the_id), array('page', 'post', 'product')) ? '' : 'target="_blank"'; echo "<{$heading} class='post-title entry-title {$css}'><a {$blank} 'title='".the_title_attribute('echo=0')."' href='".get_permalink()."' $markup>".get_the_title()."</a></{$heading}>"; ?>
Thanks again!
January 28, 2020 at 1:49 pm #1178999Hi Ismael,
Sorry but i see another problem. When I do a search, I get some suggestions at the bottom of the search field. When I click directly on a external or PDF link, it still opens in the same window/tab.
Also, when the list is rather long (try typing in “kindermishandeling”) you can’t scroll down to all the results.
I hope yu can also help me with these two issues and also telle me how to put the code in a child theme file (see thread above).
Thanks a lot again!
January 29, 2020 at 9:52 am #1179332Hi,
Glad it’s working.
Do I make a copy of the whole file and place it in my Enfold-child folder (in a subfolder includes)?
Yes, you can override the file by creating a copy of it in the child theme directory.
external or PDF link, it still opens in the same window/tab.
All pdf files in the search results open a new tab. How can we reproduce the issue? What keyword do we have to look for?
Best regards,
IsmaelJanuary 29, 2020 at 10:47 am #1179353Hi Ismael,
It’s the result list that appears when you type a word, try “kindermishandeling” and do not click <enter>.
The list is very long and won’t scrol, so you cannot see all results.
The external links and links to PDF’s are still opening in the same tab/window when you click on it from that result list.I placed a link to a screenshot in private content.
January 30, 2020 at 3:08 pm #1179911Hi,
Thank you for the info.
You’re probably talking about the AJAX search. For that, you have to modify the functions-enfold.php file. Look for the function avia_ajax_search and this particular code around line 359
$output .= "<a class ='av_ajax_search_entry {$extra_class}' href='".$link."'>";
You can add the same condition as we did previously.
$blank = in_array(get_post_type($post->ID), array('page', 'post', 'product')) ? '' : 'target="_blank"'; $output .= "<a class ='av_ajax_search_entry {$extra_class}' {$blank} href='".$link."'>";
And use this css code in the Quick CSS field to add a scrollbar in the AJAX search container.
#top #searchform .ajax_search_response { overflow-y: scroll; max-height: 500px; }
Best regards,
IsmaelFebruary 1, 2020 at 11:18 am #1180491Hi Ismael,
I think we’re almost there ;-)
So the results in the AJAX search are opening in a new tab/window now, but ALL are. I need the PAGES to open in the same window. That’s not happening now.
Also, since I added the scroll bar, the top title (in this case KENNISBANK) is not completely visible anymore.
I hope you can help me with these two issues.
Thanks a lot, again!
February 3, 2020 at 3:00 pm #1180939Hi,
Thank you for following up.
It’s not working properly because the post ID is missing. Sorry about that. We adjusted the code a bit. Please try it again.
$blank = in_array(get_post_type($post->ID), array('page', 'post', 'product')) ? '' : 'target="_blank"'; $output .= "<a class ='av_ajax_search_entry {$extra_class}' {$blank} href='".$link."'>";
Best regards,
IsmaelFebruary 4, 2020 at 12:05 pm #1181234Hi Ismael,
Yes, that’s working now.
Except I tried adding it to my child file, but then it had no effect. I changed it in the core file now. Any idea why it’s not working in my child file?
Could you also provide some extra css for the top heading in the AJAX search field? See previous thread.
Thanks again!
February 9, 2020 at 2:34 am #1182672Hi,
Sorry for the delay. To fix the heading, try to add a top padding to the ajax_search_response container.
#top #searchform .ajax_search_response { overflow-y: auto; max-height: 350px; padding-top: 15px; }
Best regards,
IsmaelFebruary 11, 2020 at 10:44 am #1183379Hi Ismael,
Thanks for the reply, I tried this before and it didn’t work then, but it does now!
So thanks, issue solved.
I still only have the problem that the functions I changed in functions-enfold.php won’t work when I copy the file to my child folder. I read on other support threads that I have to copy the function to my child functions.php file.
I’m not sure though if this will do the trick and also I’m not sure what to copy exacty to the fuctions file. Can you help me with that or would you rather that I open a new thread?Thanks again
February 12, 2020 at 5:24 am #1183748Hi,
You have to copy the whole avia_ajax_search function without the opening and closing function_exists wrapper. This is the function_exists wrapper or condition.
if(!function_exists('avia_ajax_search')) { // copy everything inside this block }
Extract or copy everything inside it and put the code in the child theme’s functions.php file.
Thank you for your patience.
Best regards,
Ismael -
AuthorPosts
- You must be logged in to reply to this topic.