我的网站有一个php头,里面有一个css动画,但我没有;我不想在某些页面上出现动画


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

有这样的方法吗?

因此,我有index.php、pagetwo.php等,在这些页面中的每一个页面中都有一个php include作为标题:

在头文件的一部分中,是一个我不想出现在某些页面上的动画。除了制作两个标题副本,一个带有动画,另一个没有动画的header2.php,有什么方法可以做到这一点吗?

感谢

您可以在include之前设置一个变量,包含的文件将检查该变量。例如:

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
}

您可以在包含的主文件中设置一个var。

例如在index.php/pagetwo.php等中:

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

在header.php中:

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

(这就是我如何在我制作的网站中设置元标题和关键字)

编辑:
显然,检查变量是否首先设置,以及您需要做的任何其他事情…等等即

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

这意味着,如果出于任何原因没有设置var,就不会出现PHP错误。在这种情况下,如果未设置或!=选择"是"将不显示动画。如果您希望在缺少var数据等情况下显示默认值,请切换此选项。

相关文章: