WebsiteBaker Support (2.8.x) > Templates, Menus & Design

PHP - execute certain code depending on ?lang=

(1/2) > >>

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[&#39;REQUEST_URI&#39;];
          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 = &#39;$section_id&#39; ");
        if($query_sections->numRows() > 0) {
            $section = $query_sections->fetchRow();
            $section_id = $section[&#39;section_id&#39;];
            $module = $section[&#39;module&#39;];
            require(WB_PATH.&#39;/modules/&#39;.$module.&#39;/view.php&#39;);
        } 
        ?>

--- 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 = &#39;$section_id&#39; ");
if($query_sec->numRows() > 0) {
$section = $query_sec->fetchRow();
$section_id = $section[&#39;section_id&#39;];
$module = $section[&#39;module&#39;];
require(WB_PATH.&#39;/modules/&#39;.$module.&#39;/view.php&#39;); //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 = &#39;$section_id&#39; ");
if($query_sec->numRows() > 0) {
$section = $query_sec->fetchRow();
$section_id = $section[&#39;section_id&#39;];
$module = $section[&#39;module&#39;];
require(WB_PATH.&#39;/modules/&#39;.$module.&#39;/view.php&#39;); //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 = &#39;$section_id&#39; ");
if($query_sec->numRows() > 0) {
$section = $query_sec->fetchRow();
$section_id = $section[&#39;section_id&#39;];
$module = $section[&#39;module&#39;];
require(WB_PATH.&#39;/modules/&#39;.$module.&#39;/view.php&#39;); //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