Jump to content

Return to home page is always to English (default) language


hansv
 Share

Recommended Posts

My multilanguage site is working very well, except for one minor flaw.   If you are on a page in an other language than English, and then go back to the home page by pressing the logo, you always return to the Englisch homepage and not to the homepage of the chosen language.  

It's the same problem as the example Tripsite on the Processwire multilanguage page, https://processwire.com/api/multi-language-support/multi-language-urls/#example ,  When you choose on e.g. the spanish language and then press on the logo it returns to the English language and not stays in the chosen Spanish language.

Anyone any idea to solve this minor flaw?

Link to comment
Share on other sites

$pages->get('/') is working fine as you can the code underneath (MarkupSimpleNavigation) 

---------------------------

_main.php

---------------------------

<div id='topnav'>
    <div class='contain-to-grid'>
        <!-- <nav class="top-bar">  -->
             <nav class="top-bar" data-topbar>
                  <ul class="title-area">
                              <li class="name">
                                            <!--substitute in your own logo or text here-->
                                            <h1>
                                                <a href="<?php echo $config->urls->root; ?>">
                                                           <img id='logo' src='<?php echo $config->urls->templates; ?>styles/images/logo.png' width='180' height='200'  alt='L' Aigle - Oostende' />
                                                </a>
                                            </h1>
                                        </li>
                                       <li class="toggle-topbar menu-icon">
                                             <a href="#"><span>menu</span></a>
                                       </li>
                 </ul>
                <section class="top-bar-section">

                   
                    <ul class="right">
                             
                   <?php                                          
                              $treeMenuTop = $modules->get("MarkupSimpleNavigation"); // load the module
                              $options = array(
                                   'max_levels' => 1,
                                   'show_root' => true
                              );
                              $rootPage = $pages->get("/");;
                              echo $treeMenuTop->render($options,null,$rootPage); // render default menu
                                                                         
                   ?>
                              <?php if($page->editable()): ?>
                                            <li class='divider'></li>
                                            <li class='has-form'>
                                                           <a class='tiny success button' href='<?php echo $config->urls->admin . "page/edit/?id=$page->id"; ?>'>Edit</a>
                                            </li>
                                            <?php endif; ?>

                                            <li class='divider show-for-small'></li>
                                            <li class='search has-form show-for-small'>
                                                           <!-- this search form only displays at mobile resolution -->
                                                           <form id='search-form-mobile' action='<?php echo $config->urls->root?>search/' method='get'>
                                                                          <input type="search" name="q" value="<?php echo $sanitizer->entities($input->whitelist('q')); ?>" placeholder="Search" />
                                                           </form>
                                            </li>
                       
<!-- devider -->
                            <li class="divider"></li>
                   
                                            <!-- languages -->
                                                                                                      
                                            <?php
                                                           // language switcher                                                                               
                                                             foreach($languages as $language) {
                                                                            if(!$page->viewable($language)) continue; // is page viewable in this language?
                                                                                           //  $url = wire('page')->localUrl($language);
                                                                            if($language->id == $user->language->id) {
                                                                                           echo "<li class='current'>";
                                                                            } else {
                                                                                           echo "<li>";
                                                                            }
                                                                            $url = $page->localUrl($language);
                                                                            $hreflang = $homepage->getLanguageValue($language, 'name');
                                                                            echo "<a hreflang='$hreflang' href='$url'>$language->title</a></li>";
                                                             }
                                           ?>
                       
                                </ul>
                        </section>
               </nav>
         </div>
</div><!--/#topnav-->
Link to comment
Share on other sites

No LostKorbrakai, the code-listing my code before I asked the question.

With this code multi-language works perfect, except pressing on the logo gives always the english page (default).  The 'landing-page' is always the English page.  In my menu, there is no 'Home'-button, the logo serves as home button

Link to comment
Share on other sites

$config->urls->root doesn't have anything to do with the pagetree, especially on multi-language setups. It's much rather intended to be used as variable if processwire is installed in the root directory ( /… ) or in a subdirectory ( /mySubdirectory/… ). 

  • Like 2
Link to comment
Share on other sites

<a href="<?php echo $pages->get('/')->url; ?>">  has no effect

I made a 'Home'-button in the menu.  

In attachement dutch-version.  When pressing on Home-menu-button, the sites stays in the dutch language.  When pressing the logo, the sites turns to the English version in stead of staying in the dutch language version.

It seems that the logo is 'outside' the multilanguage

post-3139-0-49395300-1458074057_thumb.pn

post-3139-0-92503200-1458074059_thumb.pn

Link to comment
Share on other sites

If I understand right, you use: <a href="<?php echo $config->urls->root; ?>">

but you should use: <a href="<?php echo $pages->get('/')->url; ?>">

Thx Horst, your solution is working.  After changing my _main.php I didn't upload the file.  How can I be so stupid!

Many, many thx

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...