php - PHP:在特定页面上显示/隐藏 div
问题描述
我已将以下代码添加到页面以显示我只需编写一次的通知。
PHP
<?php require $_SERVER['DOCUMENT_ROOT']."/notice.php"; ?>
HTML
<div class="notice-1">
<div class="date-event">2018-09-30 11:00</div> <!-- Hide notice when date/time expires -->
<p class="notice-22-1">Daylight Saving begins Sunday 30th Sept
</p>
</div>
但是,有时我想在特定页面上显示此消息,例如 /contact。
这就是我想出的。我是新手,所以我不知道...
PHP
<?php
if( is_page( array( "new1", "contact1" ) ) ) {
$showdiv = 'notice-1';
}
?>
注意:我已经分配了一个页面 ID(例如“contact1”)来帮助创建一个数组。
在行动:https ://www.citychurchchristchurch.co.nz/new
我不能让它工作。您能提供的任何帮助将不胜感激。谢谢。
解决方案
<?php
//list your intended pages in an array
$intended_pages = array('page1', 'page7', 'page12');
//get the current page name
$page_name= basename($_SERVER['PHP_SELF']);
//check if the current page is on the list
If(in_array($page_name, $intended_pages))
{
//current page is on the list so perform function
$showdiv = 'notice-1';
}
?>
推荐阅读
- java - Hibernate JPA @Generated 注解编译错误
- database - 使用 flask-sqlalchemy 组织数据库表
- javascript - window.screenY 上的 JS if 语句不起作用
- amazon-web-services - AWS 目标组 - 健康检查失败 - 目标路径无效
- javascript - iMacros/Javascript - 如何在 iframe 中公开 recaptcha V2 的文本区域?
- python - 在 Docker 中匀称地安装 - OSError: 找不到库 c 或加载它的任何变体 []
- java - 如何在java中使用“for each”来获取输入?
- android - 仅带有图像选项的相机意图
- gitlab-ci-runner - 如何使用 VirtualBox 设置 gitlab 运行器 - Windows 上的 Linux
- java - 我的世界插件无法识别东西