WebsiteBaker Support (2.8.x) > Templates, Menus & Design
PHP - execute certain code depending on ?lang=
Lotus:
Hello, need som PHP-help with my template.php im trying to do multinlingual. I have two sections that i want to be global. But I want them to show depending on ?lang= set.
If lang=se
show section 10
else if lang=en
show section 11
else
show section 12
I have this code but out of ideas :-D, anyone up to it?
--- Code: --- <?php
$url = $_SERVER['REQUEST_URI'];
if (strrpos($url,"hem.php")) {
?>
<img src="<?php echo TEMPLATE_DIR; ?>/images/imagebild2.gif" />
<?php
} elseif (strrpos($url,"home.php")) {
?>
<img src="<?php echo TEMPLATE_DIR; ?>/images/imagebild2.gif" />
<?php
} else {
?>
<img src="<?php echo TEMPLATE_DIR; ?>/images/imagebild.gif" />
<?php } ?>
--- End code ---
--- Code: --- <?php
$section_id = 9;
$query_sections = $database->query("SELECT section_id,module FROM ".TABLE_PREFIX."sections WHERE section_id = '$section_id' ");
if($query_sections->numRows() > 0) {
$section = $query_sections->fetchRow();
$section_id = $section['section_id'];
$module = $section['module'];
require(WB_PATH.'/modules/'.$module.'/view.php');
}
?>
--- End code ---
kweitzel:
You can just query the language directly, you don't need to go via the "Request_URI" ...
Have a look here: http://help.WebsiteBaker.org/pages/en/advanced-docu/developer-guide/variables-and-constants.php
cheers
Klaus
Lotus:
That is great news, just dont know how to acually write the code. Believe me i would have if i knew. :-D
vyni:
Hi Lotus,
try this code
--- Code: ---<?php
if (LANGUAGE==SE) {
$section_id = 10; //change this section_id for Your needings
$query_sec = $database->query("SELECT section_id,module FROM ".TABLE_PREFIX."sections WHERE section_id = '$section_id' ");
if($query_sec->numRows() > 0) {
$section = $query_sec->fetchRow();
$section_id = $section['section_id'];
$module = $section['module'];
require(WB_PATH.'/modules/'.$module.'/view.php'); //statt view.php die alternative eintragen!
}
} else if (LANGUAGE==EN) {
$section_id = 11; //change this section_id for Your needings
$query_sec = $database->query("SELECT section_id,module FROM ".TABLE_PREFIX."sections WHERE section_id = '$section_id' ");
if($query_sec->numRows() > 0) {
$section = $query_sec->fetchRow();
$section_id = $section['section_id'];
$module = $section['module'];
require(WB_PATH.'/modules/'.$module.'/view.php'); //statt view.php die alternative eintragen!
}
} else {
$section_id = 12; //change this section_id for Your needings
$query_sec = $database->query("SELECT section_id,module FROM ".TABLE_PREFIX."sections WHERE section_id = '$section_id' ");
if($query_sec->numRows() > 0) {
$section = $query_sec->fetchRow();
$section_id = $section['section_id'];
$module = $section['module'];
require(WB_PATH.'/modules/'.$module.'/view.php'); //statt view.php die alternative eintragen!
}
}
<?
--- End code ---
maybe it is does what Your are looking for.
regards from Himberg, near Vienna
Lotus:
--- Quote from: vyni on December 15, 2008, 06:06:35 PM ---maybe it is does what Your are looking for.
regards from Himberg, near Vienna
--- End quote ---
This code is so great I can´t believe my eyes :-D, thanx Himberg! This opens up lots of possibilities when making templates, until now i solved all this issues with another template, but always thought it was "not quite right" doing so.
Regards Sweden!
Navigation
[0] Message Index
[#] Next page
Go to full version