douyingp82418 2012-02-15 20:58
浏览 77

如果cookie不存在,则显示视频

Just a warning, I am totally new to PHP and coding in general so please bear with me.

Here is what I am attempting to do: Our company's wordpress website ( http://www.vectormedia.com ) uses lightbox to display a video when the homepage is loaded. I'd like to make it so that if you have visited the website in the past week, the video will not appear.

Here is my code:

At the very top of the header.php of my wordpress theme is the function to create the cookie:

<?php
function cookies() //Sets cookie function for video
{
$expire = time()+60*60*24*7; //cookie expiration (7days)
setcookie("video", "vector", $expire);
}
?>

Here is the variable that will load the video embedded in lightbox (also located in header.php):

<?php
//defines javaload as lightbox script with embeded video
$javaload = '<script type="text/javascript">
jQuery(document).ready(function(){

jQuery.lightbox("https://www.vimeo.com/36697123");

});
</script>'   
?>

Here is the If statement located in the footer.php that checks to see if the cookie exists and if we are on the homepage, if true then load the video and set the cookie:

<?php
if ( !isset($_COOKIE["video"])) && (is_front_page());
echo $javaload
echo cookies();
?>

The problems are:

a) this code simply doesn't work.
b) it's also breaking my submenu rollovers

And my questions are:

a) why doesn't this work?
b) why is it breaking my menu?
c) is there a better way to accomplish this?

Any help will be greatly appreciated, thanks in advance.

  • 写回答

2条回答 默认 最新

  • dongpin2969 2012-02-15 21:03
    关注

    semi-colon after:

    echo $javaload

    and remove the semi-colon after the if statement and use {} for the if tag if you want to only set a cookie when there is no cookie.

    评论

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?