WebsiteBaker Logo
  • *
  • Templates
  • Help
  • Add-ons
  • Download
  • Home
*
Welcome, Guest. Please login or register.

Login with username, password and session length
 

News


WebsiteBaker 2.13.6 is now available!


Will it continue with WB? It goes on! | Geht es mit WB weiter? Es geht weiter!
https://forum.websitebaker.org/index.php/topic,32340.msg226702.html#msg226702


The forum email address board@websitebaker.org is working again
https://forum.websitebaker.org/index.php/topic,32358.0.html


R.I.P Dietmar (luisehahne) and thank you for all your valuable work for WB
https://forum.websitebaker.org/index.php/topic,32355.0.html


* Support WebsiteBaker

Your donations will help to:

  • Pay for our dedicated server
  • Pay for domain registration
  • and much more!

You can donate by clicking on the button below.


  • Home
  • Help
  • Search
  • Login
  • Register

  • WebsiteBaker Community Forum »
  • WebsiteBaker Support (2.8.x) »
  • Droplets & Snippets »
  • Droplet: Language Switcher URL
  • Print
Pages: [1]   Go Down

Author Topic: Droplet: Language Switcher URL  (Read 4583 times)

Offline lash

  • Posts: 1
Droplet: Language Switcher URL
« on: February 23, 2011, 01:39:27 PM »
Hi... i build a little droplet based on the Language Switcher Snippet. The code is much shorter but it uses the same technique. So the requirements are the same. The menu trees of the different languages have to be the same. If there's no corresponding page use a dummy page (with visibility set to hidden or none). In this case the language root is returned.
You also have to set the language attribute of all pages correctly. Normally you only have to do this for the root entries (EN, DE, ...), on all other pages it is automatically set to its parent value.

The droplet only returns the URL, so you have to build the links yourself!

Code: [Select]
<?php

global $database, $wb;

$url = WB_URL.$_SERVER[&#39;PHP_SELF&#39;];

if (strtolower(LANGUAGE) != strtolower($lang)) {

// get additional page info
$sql = "SELECT position, menu FROM ".TABLE_PREFIX."pages WHERE page_id = ".PAGE_ID;
$get_content = $database->query($sql);
$page_info = $get_content->fetchRow();

// get link
$sql = "SELECT link, visibility FROM ".TABLE_PREFIX."pages ";
$sql .= "WHERE language = &#39;".strtoupper($lang)."&#39; AND position = ".$page_info[&#39;position&#39;]." ";
$sql .= "AND level = ".LEVEL." AND menu = ".$page_info[&#39;menu&#39;];

$get_content = $database->query($sql);
$content = $get_content->fetchRow();

if ($content && $content[&#39;visibility&#39;] === &#39;public&#39;) {
$url = WB_URL.PAGES_DIRECTORY.$content[&#39;link&#39;].PAGE_EXTENSION;
}
else {
$url = WB_URL.PAGES_DIRECTORY.&#39;/&#39;.strtolower($lang).PAGE_EXTENSION;
}
}
return 
$url;

?>


Just insert the code (without <?php ... ?>) into the droplet creator and call it with [[dropletname?lang=(code)]];
« Last Edit: February 23, 2011, 01:46:07 PM by lash »
Logged

  • Print
Pages: [1]   Go Up
  • WebsiteBaker Community Forum »
  • WebsiteBaker Support (2.8.x) »
  • Droplets & Snippets »
  • Droplet: Language Switcher URL
 

  • SMF 2.0.19 | SMF © 2017, Simple Machines
  • XHTML
  • RSS
  • WAP2