简体   繁体   English

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

[英]If cookie is not present, display video

Just a warning, I am totally new to PHP and coding in general so please bear with me. 只是警告,我一般都不熟悉PHP和编码,因此请耐心等待。

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. 这是我要尝试做的事情:加载首页后,我们公司的wordpress网站( http://www.vectormedia.com )使用灯箱显示视频。 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: 我的wordpress主题的header.php的最顶部是创建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): 这是将加载嵌入灯箱(也位于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: 这是位于footer.php中的If语句,用于检查cookie是否存在以及我们是否在首页上,如果为true,则加载视频并设置cookie:

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

The problems are: 问题是:

a) this code simply doesn't work. a)此代码根本不起作用。
b) it's also breaking my submenu rollovers b)这也打破了我的子菜单翻转

And my questions are: 我的问题是:

a) why doesn't this work? a)为什么不起作用?
b) why is it breaking my menu? b)为什么会打断我的菜单?
c) is there a better way to accomplish this? c)是否有更好的方法可以做到这一点?

Any help will be greatly appreciated, thanks in advance. 任何帮助将不胜感激,在此先感谢。

semi-colon after: 分号后:

echo $javaload 回声$ 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. 并在if语句之后删除分号,如果只想在没有cookie的情况下设置cookie,则对if标记使用{}。

Should be 应该

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

But im not sure thats going to trigger the lightbox in that case you'd have to do it like this 但是在这种情况下,我不确定那是否会触发灯箱,您必须这样做

<script>
function play_video() {
jQuery.lightbox("https://www.vimeo.com/36697123");
}
</script>

then change $javaload to echo out play_video(); 然后更改$ javaload以回显play_video();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM