Viewing 19 posts - 1 through 19 (of 19 total)
  • Author
    Posts
  • #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!

    #1176065

    Hey JantienM,

    Can you please give us the link to the page with the issue?

    Best regards,
    Victoria

    #1176636

    It’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.
    #1177262

    Hi 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,
    Victoria

    #1177495

    Thanks 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!

    #1177978

    Hi,

    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,
    Ismael

    #1178100

    Thanks 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!

    #1178557

    Hi,

    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,
    Ismael

    #1178722

    Hi 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!

    #1178999

    Hi 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!

    #1179332

    Hi,

    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,
    Ismael

    #1179353

    Hi 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.

    #1179911

    Hi,

    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,
    Ismael

    #1180491

    Hi 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!

    #1180939

    Hi,

    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,
    Ismael

    #1181234

    Hi 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!

    #1182672

    Hi,

    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,
    Ismael

    #1183379

    Hi 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

    #1183748

    Hi,

    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

Viewing 19 posts - 1 through 19 (of 19 total)
  • You must be logged in to reply to this topic.