0

我找到了这段代码:

<?php global $language; ?>
<?php global $theme_path; ?>

<ul class="language-switcher-locale-url">
    <?php $languages = language_list() ?>
    <?php foreach($languages as $lang): ?>
    <?php $active = $language->language == $lang->language ? " active" : ""; ?>
    <li class="<?php echo $lang->language ?><?php echo $active ?>">
        <a href="/<?php echo $lang->prefix ?>">
            <img src="/<?php echo $theme_path ?>/images/flags/<?php echo $lang->language ?>.png" alt="<?php echo $lang->language ?>"/>
        </a>
    </li>
    <?php endforeach ?>
</ul>

这会将我从mywebsite.com/de/current_page所选语言重定向到 ex。mywebsite.com/en

我可以做些什么让我的代码将我重定向到mywebsite.com/en/current_page

4

1 回答 1

2

您应该尝试使用 Drupal 提供的url()request_path()函数,也许这样的事情会起作用:

<?php global $language; global $theme_path; $languages = language_list() ?>

<ul class="language-switcher-locale-url">                                                                                                                                                                           
  <?php foreach($languages as $lang): ?>
    <?php $active = $language->language == $lang->language ? " active" : ""; ?>
    <li class="<?php echo $lang->language ?><?php echo $active ?>">
      <a href="<?php echo url(request_path(), array('language' => $lang)); ?>">
        <img src="/<?php echo $theme_path ?>/images/flags/<?php echo $lang->language ?>.png" alt="<?php echo $lang->language ?>"/>
      </a>
    </li>
  <?php endforeach ?>
</ul>
于 2013-10-09T15:07:25.870 回答