简体   繁体   中英

I have a php header for my site, with a css animation in it, but I don't want to animation to occur on certain pages

Is there anyway to do this?

So I have index.php, pagetwo.php, etc. and in each of these pages is a php include for the header:

in that header file in part, is an animation that I don't want to occur on certain pages. Short of making two copies of the header, one with the animation, and a header2.php without it, is there any way to accomplish this?

Thanks

You could set a var in your main files which is picked up in the include.

eg in index.php/pagetwo.php etc:

$AnimateOrNot = 'yes';
include_once('header.php');

in header.php:

if ($AnimateOrNot == 'yes)
  {
    // show animate
  }

(This is how I set the meta title and keywords throughout sites I make)

EDIT:
Obviously check if the variables are set first, and anything else you need to do...etc ie

if (isset($AnimateOrNot) && $AnimateOrNot == 'yes)
  {
    // show animate
  }

This will mean if for any reason the var is not set there will be no PHP errors. It also means the default action in this case if it's not set or != to "Yes" will be not to show animation. Switch this if you want the default to show in case of missing var data etc. up to you.

You can set a variable before the include that the included file will check. For example:

header.php

<?php if (!empty($animation)): ?>
<style>
...
</style>
<?php endif; ?>

animate.php

$animation = TRUE;
include 'header.php';

dont_animate.php

$animation = FALSE;
include 'header.php';
if($_SERVER['PATH_INFO']!="/path/to/pagetwo.php")
{
     //show animation
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM