Support » Plugin: Polylang » [How to] Search results landing page with custom header for each language

  • Resolved uskro

    (@uskro)


    Hello!

    I tried finding something similar in the support pages, but I couldn’t. I couldn’t find something useful and I couldn’t go through all 115 pages of them. Neither did I find on google.

    I’m using the latest version of both WordPress and Polylang, and my homepages links to static pages on all 5 languages of my installation.

    I’m running a theme I built myself, for a customer who wants menus that are counter-intuitive, so they don’t match the structure of the pages, therefore there is no menu function installed in the theme, it’s all made manually.

    The (hopefully) last issue I’m having is finding a way to direct search results to language specific pages. So if I’m searching in English, I want the results to be shown in category-en.php not the default category.php or index.php which use the default Romanian language for Header / Sidebar / Footer.

    This is what I used to make the search form in the php files:

    <form action="" method="get">
       <input type="text" value="<?php the_search_query(); ?>" name="s" placeholder="Caută" class="footer-search-input"/>
       <input type="button" value="" class="footer-search-submit"/>
    </form>

    The search is working fine, I’m only receiveing language specific results. The only issue is the fact that it’s using a template for the default language.

    For category uses I used functions.php, with something I did find in the support forums, that looks something like this:

    add_filter( 'category_template', 'my_category_template' );
    function my_category_template($template) {
    
    if(is_category(array(26,36,50,56,474,86,96,106,116))){
      $template = locate_template(array('category-en.php'));
      return $template;
    }

    Here’s a link to the project.

    Your help will be much appreciated!
    ~ uskro

    https://wordpress.org/plugins/polylang/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter uskro

    (@uskro)

    Here to answer my own question, I used an answer from one of the creator’s discussions with another fellow that can be found here, which could have saved me a lot of troublem with all those categories that I had to manually index.

    But, nevertheless, this is what I ended up with.

    If you want to switch header/footer/sidebar or other elements between 2 languages, where you have the files header.php for your default language (let’s say English) and header-fr.php for your default language (let’s say French), use:

    <?php
    $currentlang = get_bloginfo('language');
    if($currentlang=="en-GB"): get_header();
    else: get_header('fr');
    endif;
    ?>

    If you want to switch header/footer/sidebar or other elements between 3 or more languages, where you have the files header.php for your default language (let’s say English) and header-fr.php for your default language (let’s say French) and header-de.php for German/Deutsch, use:

    <?php
     $currentlang = get_bloginfo('language');
     if($currentlang=="en-GB"): get_header();
     elseif($currentlang=="fr-FR"): get_header('fr');
     else: get_header('de');
     endif;
    ?>

    Feel free to add as many elseif lines as you need.

    This can also work with other functions, like this:

    <?php
    $currentlang = get_bloginfo('language');
     if($currentlang=="en-GB"): _e ('We apologize, but we did not manage to match your query.');
     elseif($currentlang=="fr-FR"): _e ('Nous nous excusons, mais nous ne sommes pas parvenus pour correspondre à votre requête.');
     elseif($currentlang=="hu-HU"): _e ('Elnézést kérünk, de nem sikerült megfelelő lekérdezést.');
     elseif($currentlang=="de-DE"): _e ('Es tut uns leid, aber wir konnten nicht ihren vorstellungen entsprach.');
     else: _e ('Ne cerem scuze, nu am găsit nicio postare conform criteriilor selectate.');
     endif;
    ?>

    Or it can work with plain text, like this:

    <p>
     <?php
      $currentlang = get_bloginfo('language');
      if($currentlang=="en-GB"): echo "This is<br/>text";
      elseif($currentlang=="fr-FR"): echo "Ceci est un<br/>texte";
      elseif($currentlang=="hu-HU"): echo "Ez a<br/>szöveg";
      elseif($currentlang=="de-DE"): echo "Dies ist<br/>text";
      else: echo "Acesta este<br/>text";
      endif;
     ?>
    </p>

    Thanks so much for the plugin and help in the forums, I’ve translated the plugin to Romanian as well, I just need to figure out where/how to send it to you. If I don’t find where, I’ll leave a download link here for a few days.

    polylang-ro_RO.mo
    polylang-ro_RO.po

    Cheers!

    Plugin Author Chouby

    (@chouby)

    Hi!

    Thank you very much for the Romanian translation. I already downloaded it and will add it in the next version.

    As you certainly noticed, I offer a link to translator’s website. If you are interested, you can contact me at: https://polylang.wordpress.com/contact/

    I am trying this method for my search results page and it doesn’t seem to be working. I used this code for header and footer:

    <?php $currentlang = get_bloginfo('language');
     if($currentlang=="en_US"): get_header();
     elseif($currentlang=="fr_FR"): get_header('fr');
     elseif($currentlang=="en_GB"): get_header('uk');
     else: get_header('de');
     endif; ?>

    It keeps defaulting to the last else statement – else: get_header(‘de’);. Also ho,w do I change navigation in header to language specific menus?

    I have the Geo specific menus (nav) working but the conditional PHP for displaying the correct header in my search.php template as show above is not working and keeps showing the headers and footers for DE for every language.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[How to] Search results landing page with custom header for each language’ is closed to new replies.