首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用PHP在新闻时段显示DIV

使用PHP在新闻时段显示DIV
EN

Stack Overflow用户
提问于 2015-05-09 00:54:20
回答 1查看 47关注 0票数 0

我有一个wordpress网站。我需要在新闻时段展示DIV。所以我在模板函数中有一个函数。它看起来是这样的:

代码语言:javascript
复制
function kiroj_live_news() {
$week_day = date('w');
$current_time = date('Hi');

$show_news_div = false;
if ($week_day >= 1 && $week_day <= 5)
{
  if (($current_time >= '0430' && $current_time <= '0800') || ($current_time >= '1200' && $current_time <= '1300') || ($current_time >= '1700' && $current_time <= '1830') || ($current_time >= '2300' && $current_time <= '2330'))
  {
    $show_news_div = true;
  }
}
if ($week_day == 6)
{
  if (($current_time >= '0700' && $current_time <= '0830') || ($current_time >= '1700' && $current_time <= '1800') || ($current_time >= '1830' && $current_time <= '1900') || ($current_time >= '2300' && $current_time <= '2330'))
  {
    $show_news_div = true;
  }
}

if ($week_day == 0)
{
  if (($current_time >= '0600' && $current_time <= '0700') || ($current_time >= '1700' && $current_time <= '1800') || ($current_time >= '1830' && $current_time <= '1900') || ($current_time >= '2300' && $current_time <= '2359'))
  {
    $show_news_div = true;
  }
}
}

在我想要显示我的DIV的区域,我有一个if:

代码语言:javascript
复制
<?php 
        $display = kiroj_live_news ();

        if ($display)
        {
          ?>
            <div class="live-news"><a href="http://www.kirotv.com/videos/news/kiro-newscast-hd2/vCYwYn/" target="_blank">Breaking News</a></div>
          <?php
        }

    ?>

我已经更改了主函数中的时间,尝试了PHP手册(http://php.net/manual/en/function.date.php)中的其他日期()格式,但无法显示DIV值。有人能帮上忙吗?

EN

回答 1

Stack Overflow用户

发布于 2015-05-09 00:56:16

代码语言:javascript
复制
function kiroj_live_news() {

    //your code here

    ....

    return $show_news_div;

}

$display = kiroj_live_news();

......

您的函数不返回任何内容-因此它始终为FALSE

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30129034

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档