dorbmd1177 2015-05-21 14:01 采纳率: 100%
浏览 38
已采纳

包括取决于身体类别

I'm trying to figure out how to check for a single class on the body tag then include a file.

My header.php contains:

</head>
<?php $class = BODY_CLASS; ?>
<body class="<?php echo $class; ?>" id="top">

And in the body:

<?php if (isset($class) && $class == 'work') { ?>
    <?php include( $_SERVER['DOCUMENT_ROOT'] . MODULES . "_social.php"); ?>
<?php }; ?>

This works fine so long as I only have a single class on the body tag, but what if I have multiple tags?

for instance my body tag outputs this:

<body id="top" class="work project1">

How can I check for the work even if other classes exist?

  • 写回答

3条回答 默认 最新

  • duanmei1894 2015-05-21 14:04
    关注

    Just change your if statement a bit and explode() your $class, by a space to then search in the array for the value with in_array(), e.g.

    if (in_array("work", explode(" ", $class))) {
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记