Jump to content

[SOLVED] can anyone explain this php code?


lordrt

Recommended Posts

Hello all

Am trying to modify a php template for my website, which has multilanguage support. I in fact have to use 2 logos, one for each language french and german, and am using drupal to create the site.

the following code is taken from a file called page.tpl.php

 

<div id="logo-floater">
          <h1> <a href="<?php print check_url($front_page); ?>">
            <?php if ($logo): ?> 
              <img src="<?php print check_url($logo); ?>" 
                   title="<?php print check_plain($site_name) . check_plain($site_slogan); ?>" 
                   alt="<?php print check_plain($site_name) . check_plain($site_slogan); ?>" id="logo" />
            <?php endif; ?>
            

 

can anyone pls explain me this part of code, what it is doing really?

Link to comment
Share on other sites

The check_url function just takes the URL and makes sure its safe to use, and the check_plain function is just used to encode special characters, so it changes the & symbol to &

 

The if($logo) part is just there to determine if the script has a URL to a particular logo.

 

If your trying to display logo 1 for the first language and logo 2 for a second language try the following

 

<div id="logo-floater">
          <?php
if($language->name == "Dutch") {
   $logo = 'location_of_dutch_logo';
}
elseif($language->name == "English") {
$logo = 'location_of_english_logo';
}
          ?>
          <h1> <a href="<?php print check_url($front_page); ?>">
            <?php if ($logo): ?> 
              <img src="<?php print check_url($logo); ?>" 
                   title="<?php print check_plain($site_name) . check_plain($site_slogan); ?>" 
                   alt="<?php print check_plain($site_name) . check_plain($site_slogan); ?>" id="logo" />
            <?php endif; ?>
            

 

In this code you have to know the value of the $language->name variable but you can also change out the $language->name == "English" part with $language->language == 'en' which would be might be more stable and easier to use

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.