PHP:在特定页面上显示/隐藏Div
我在页面中添加了以下代码,以显示只需编写一次的通知 PHPPHP:在特定页面上显示/隐藏Div,php,Php,我在页面中添加了以下代码,以显示只需编写一次的通知 PHP HTML 2018-09-30 11:00 夏时制于9月30日星期日开始 但是,我有时希望在特定页面上显示此消息,例如/contact 这是我想到的。我是新手,所以我不知道 PHP 注意:我已经分配了一个页面id(例如“contact1”)来帮助创建一个数组 在行动中: 我不能让它工作。如果您能提供任何帮助,我们将不胜感激。谢谢。 <?php //list your intended pages in
HTML
2018-09-30 11:00
夏时制于9月30日星期日开始
但是,我有时希望在特定页面上显示此消息,例如/contact
这是我想到的。我是新手,所以我不知道
PHP
注意:我已经分配了一个页面id(例如“contact1”)来帮助创建一个数组
在行动中:
我不能让它工作。如果您能提供任何帮助,我们将不胜感激。谢谢。
<?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';
}
?>
什么是是页面
?你在写Wordpress吗?谢谢你的回复。我想我对WordPress的解决方案感到困惑(显示我在这方面有多糟糕)。我没有用WordPress。我可以使用其他方法吗?什么是Is\u page
?你在写Wordpress吗?谢谢你的回复。我想我对WordPress的解决方案感到困惑(显示我在这方面有多糟糕)。我没有用WordPress。我有没有别的选择?谢谢你,鲍比。我好像没法让它工作。几个问题。。。1.是否可以将其添加到/notice.php文档中?2.这些页面是按“页面地址”标识为“/new”还是按“页面id”标识为“new1”?3.为了清楚起见,我没有使用WordPress,以防我的文章有误导性。我不确定你的代码是否包含了这方面的内容。无论如何,再次感谢你的帮助!您可以将其作为单个文件,然后include()代码>此选项适用于需要显示通知的所有页面。然后,$destinated_pages
将在一个数组中包含您希望通知显示的所有页面的名称,例如:login.php、about.php、dashbord.html等。我好像没法让它工作。几个问题。。。1.是否可以将其添加到/notice.php文档中?2.这些页面是按“页面地址”标识为“/new”还是按“页面id”标识为“new1”?3.为了清楚起见,我没有使用WordPress,以防我的文章有误导性。我不确定你的代码是否包含了这方面的内容。无论如何,再次感谢你的帮助!您可以将其作为单个文件,然后include()代码>此选项适用于需要显示通知的所有页面。然后,$designed_pages
将在一个数组中包含您希望通知显示的所有页面的名称,例如:login.php、about.php、dashbord.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>
<?php
if( is_page( array( "new1", "contact1" ) ) ) {
$showdiv = 'notice-1';
}
?>
<?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';
}
?>