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) »
  • Templates, Menus & Design »
  • PHP - execute certain code depending on ?lang=
  • Print
Pages: [1]   Go Down

Author Topic: PHP - execute certain code depending on ?lang=  (Read 5286 times)

Lotus

  • Guest
PHP - execute certain code depending on ?lang=
« on: December 15, 2008, 04:00:58 PM »
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: [Select]
        <?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 } ?>
       
Code: [Select]
        <?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;);
        } 
        ?>

Logged

Offline kweitzel

  • WebsiteBaker Org e.V.
  • **
  • Posts: 6983
  • Gender: Male
Re: PHP - execute certain code depending on ?lang=
« Reply #1 on: December 15, 2008, 04:07:00 PM »
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
Logged

Lotus

  • Guest
Re: PHP - execute certain code depending on ?lang=
« Reply #2 on: December 15, 2008, 04:32:05 PM »
That is great news, just dont know how to acually write the code. Believe me i would have if i knew. :-D
Logged

vyni

  • Guest
Re: PHP - execute certain code depending on ?lang=
« Reply #3 on: December 15, 2008, 06:06:35 PM »
Hi Lotus,

try this code

Code: [Select]
<?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!
}
}
<?

maybe it is does what Your are looking for.

regards from Himberg, near Vienna
Logged

Lotus

  • Guest
Re: PHP - execute certain code depending on ?lang=
« Reply #4 on: December 16, 2008, 08:39:18 AM »
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


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!
Logged

Offline pcwacht

  • Posts: 2923
  • Gender: Male
    • Dutch ICT info
Re: PHP - execute certain code depending on ?lang=
« Reply #5 on: December 16, 2008, 09:53:05 AM »
Cleaned it up a bit for clarity and readablitity

Code: [Select]
<?php
if (LANGUAGE==SE) { 
    
$section_id = 10;   //change this section_id for Your needings
} elseif (LANGUAGE==EN) {
    
$section_id = 11; //change this section_id for Your needings
} else {
    
$section_id = 12; //change this section_id for Your needings
}
if (isset(
$section_id)) { // Maker sure section isset
    
$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!
    
}
}
<?

Have fun,
John

Logged
http://www.ictwacht.nl = Dutch ICT info
http://www.pcwacht.nl = My first
both still work in progress, since years.....

  • Print
Pages: [1]   Go Up
  • WebsiteBaker Community Forum »
  • WebsiteBaker Support (2.8.x) »
  • Templates, Menus & Design »
  • PHP - execute certain code depending on ?lang=
 

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