Change according to page

1

Hello. I need the logo of the site to change according to the page that the user visits. I have a site made in PHP in which the top is include . So I thought about changing the logo via Javascript.

I set ID="logo" to img and ID to body of pages that will have a different logo. So I hoped that through If / Else , checking whether or not there was ID in body , src of the image changed. But it's not rolling. I'm not a programmer and I came here searching on Google. rs

Here are my codes:

HTML

<img id="logo" src="<?=$img_dir?>/logo_ultraclimber-resgate.png" alt="Ultra Climber Treinamentos e Serviços" />

JS

<script type="text/javascript">
if ('body[id="treina"]') {
    document.getElementById("logo").src='_include/images/logo_ultraclimber-treinamentos.png';
} if else ('body[id="serv"]') {
    document.getElementById("logo").src='_include/images/logo_ultraclimber-servicos.png';
} else {
    document.getElementById("logo").src='_include/images/logo_ultraclimber-resgate.png';
}

Thanks for the help! =]

    
asked by anonymous 08.03.2015 / 19:46

1 answer

3

Doing this in a JS site in PHP is a bit of a hassle. Ideally, this should be resolved in PHP itself.

For example, creating a variable before include:

paginaresgate.php

<?php
   $logo = 'logo_ultraclimber-resgate.png';
   include( '__topo.php' );

   ... resto da pagina

And in% w / o you simply change the line with the hardcoded logo for something like that, which arrows a variable, or uses the user supplied:

__ top.php

<?php
   ... 
   if ( !isset( $logo ) ) $logo = 'logo_default.png'; // caso não seja setado na página
   echo '<img id="logo" src="'.$img_dir.'/'.$logo.' alt="ultraclimber...">';
   ...


Note that there are many other ways to solve the problem, but this proposal serves not only for the logo, but also for __topo.php of the page, <title> of the image or any other variable data that do not significantly change the top structure.

    
08.03.2015 / 20:42