PHP中的Javascript不是';行不通
我正在使用超大jquery脚本为我的wordpress页面使用各种滑动背景 现在,我想为每个站点制作不同的幻灯片,需要一个php if请求 我的代码:PHP中的Javascript不是';行不通,javascript,php,jquery,wordpress,supersized,Javascript,Php,Jquery,Wordpress,Supersized,我正在使用超大jquery脚本为我的wordpress页面使用各种滑动背景 现在,我想为每个站点制作不同的幻灯片,需要一个php if请求 我的代码: <?php if ( is_page(array('Restaurant'))) { echo"<script type="text/javascript"> jQuery(function($) { $.supersized({ // Fun
<?php if ( is_page(array('Restaurant'))) {
echo"<script type="text/javascript">
jQuery(function($) {
$.supersized({
// Functionality
slide_interval: 9000, // Length between transitions
transition: 1, // 0-None, 1-Fade, 2-Slide Top, 3-Slide Right, 4-Slide Bottom, 5-Slide Left, 6-Carousel Right, 7-Carousel Left
transition_speed: 1400, // Speed of transition
// Components
slide_links: 'blank', // Individual links for each slide (Options: false, 'num', 'name', 'blank')
slides: [ // Slideshow Images
{
image: 'http://www.hotel-zur-traube.eu/wp-content/themes/hotelzurtraube/images/bg.jpg',
title: 'Hotel-Pension-Restaurant Zur Traube in Altenahr'
}, {
image: 'http://www.hotel-zur-traube.eu/wp-content/themes/hotelzurtraube/images/bg2.jpg',
title: 'Hotel-Pension-Restaurant Zur Traube in Altenahr'
}, {
image: 'http://www.hotel-zur-traube.eu/wp-content/themes/hotelzurtraube/images/bg3.jpg',
title: 'Hotel-Pension-Restaurant Zur Traube in Altenahr'
},
]
});
});
</script>";}
?>
将
更改为
您使用的是双引号-与打开和关闭echo
语句相同。首先,我可以建议您删除代码的echo
<?php if ( is_page(array('Restaurant'))) { ?>
<script type="text/javascript">
jQuery(function($){
$.supersized({
// Functionality
slide_interval : 9000, // Length between transitions
transition : 1, // 0-None, 1-Fade, 2-Slide Top, 3-Slide Right, 4-Slide Bottom, 5-Slide Left, 6-Carousel Right, 7-Carousel Left
transition_speed : 1400, // Speed of transition
// Components
slide_links : 'blank', // Individual links for each slide (Options: false, 'num', 'name', 'blank')
slides : [ // Slideshow Images
{image : 'http://www.hotel-zur-traube.eu/wp-content/themes/hotelzurtraube/images/bg.jpg', title : 'Hotel-Pension-Restaurant Zur Traube in Altenahr'},
{image : 'http://www.hotel-zur-traube.eu/wp-content/themes/hotelzurtraube/images/bg2.jpg', title : 'Hotel-Pension-Restaurant Zur Traube in Altenahr'},
{image : 'http://www.hotel-zur-traube.eu/wp-content/themes/hotelzurtraube/images/bg3.jpg', title : 'Hotel-Pension-Restaurant Zur Traube in Altenahr'},
]
});
});
</script>
<?php } ?>
jQuery(函数($){
美元。超大({
//功能性
滑动间隔:9000,//过渡之间的长度
转换:1、//0-无、1-淡入、2-顶部滑动、3-右侧滑动、4-底部滑动、5-左侧滑动、6-右侧旋转木马、7-左侧旋转木马
过渡速度:1400,//过渡速度
//组成部分
幻灯片链接:'空白',//每张幻灯片的单个链接(选项:false、'num、'name、'blank')
幻灯片:[//幻灯片放映图像
{图像:'http://www.hotel-zur-traube.eu/wp-content/themes/hotelzurtraube/images/bg.jpg,标题:“阿尔特纳尔祖尔特劳伯养老金餐厅酒店”,
{图像:'http://www.hotel-zur-traube.eu/wp-content/themes/hotelzurtraube/images/bg2.jpg,标题:“阿尔特纳尔祖尔特劳伯养老金餐厅酒店”,
{图像:'http://www.hotel-zur-traube.eu/wp-content/themes/hotelzurtraube/images/bg3.jpg,标题:“阿尔特纳尔祖尔特劳伯养老金餐厅酒店”,
]
});
});
您将拥有代码的最佳可见性,并且不会出现引号错误。使用此方法检查您的控制台,并告诉我们您是否有错误您的代码无法工作,因为您没有转义字符串。
当使用双引号作为开始引号和结束引号时,必须转义其中的其他双引号。
这也适用于单引号,这意味着您必须转义使用单引号作为开始引号和结束引号的字符串中的单引号
注意:不需要转义单引号内的双引号和双引号内的单引号
您需要像这样转义您的引用:
<?php
if(is_page(array('Restaurant'))) {
echo("<script type=\"text/javascript\">
jQuery(function($) {
$.supersized({
// Functionality
slide_interval: 9000,
// Length between transitions
transition: 1,
// 0-None, 1-Fade, 2-Slide Top, 3-Slide Right, 4-Slide Bottom, 5-Slide Left, 6-Carousel Right, 7-Carousel Left
transition_speed: 1400,
// Speed of transition
// Components
slide_links: 'blank',
// Individual links for each slide (Options: false, 'num', 'name', 'blank')
slides: [
// Slideshow Images
{
image: 'http://www.hotel-zur-traube.eu/wp-content/themes/hotelzurtraube/images/bg.jpg',
title: 'Hotel-Pension-Restaurant Zur Traube in Altenahr'
}, {
image: 'http://www.hotel-zur-traube.eu/wp-content/themes/hotelzurtraube/images/bg2.jpg',
title: 'Hotel-Pension-Restaurant Zur Traube in Altenahr'
}, {
image: 'http://www.hotel-zur-traube.eu/wp-content/themes/hotelzurtraube/images/bg3.jpg',
title: 'Hotel-Pension-Restaurant Zur Traube in Altenahr'
}
]
});
});
</script>");
} ?>
<?php if(is_page(array('Restaurant'))) { ?>
<script type="text/javascript">
jQuery(function($) {
$.supersized({
// Functionality
slide_interval: 9000,
// Length between transitions
transition: 1,
// 0-None, 1-Fade, 2-Slide Top, 3-Slide Right, 4-Slide Bottom, 5-Slide Left, 6-Carousel Right, 7-Carousel Left
transition_speed: 1400,
// Speed of transition
// Components
slide_links: 'blank',
// Individual links for each slide (Options: false, 'num', 'name', 'blank')
slides: [
// Slideshow Images
{
image: 'http://www.hotel-zur-traube.eu/wp-content/themes/hotelzurtraube/images/bg.jpg',
title: 'Hotel-Pension-Restaurant Zur Traube in Altenahr'
}, {
image: 'http://www.hotel-zur-traube.eu/wp-content/themes/hotelzurtraube/images/bg2.jpg',
title: 'Hotel-Pension-Restaurant Zur Traube in Altenahr'
}, {
image: 'http://www.hotel-zur-traube.eu/wp-content/themes/hotelzurtraube/images/bg3.jpg',
title: 'Hotel-Pension-Restaurant Zur Traube in Altenahr'
}
]
});
});
</script>
<? } ?>
<?php if(is_page(array('Restaurant'))) { ?>
<script type="text/javascript">
jQuery(function($) {
$.supersized({
slide_interval: 9000,
transition: 1,
transition_speed: 1400,
slide_links: 'blank',
slides: [
{
image: 'http://www.hotel-zur-traube.eu/wp-content/themes/hotelzurtraube/images/bg.jpg',
title: 'Hotel-Pension-Restaurant Zur Traube in Altenahr'
}, {
image: 'http://www.hotel-zur-traube.eu/wp-content/themes/hotelzurtraube/images/bg2.jpg',
title: 'Hotel-Pension-Restaurant Zur Traube in Altenahr'
}, {
image: 'http://www.hotel-zur-traube.eu/wp-content/themes/hotelzurtraube/images/bg3.jpg',
title: 'Hotel-Pension-Restaurant Zur Traube in Altenahr'
}
]
});
});
</script>
<? } ?>
要使代码看起来更整洁,可以删除如下注释:
<?php
if(is_page(array('Restaurant'))) {
echo("<script type=\"text/javascript\">
jQuery(function($) {
$.supersized({
// Functionality
slide_interval: 9000,
// Length between transitions
transition: 1,
// 0-None, 1-Fade, 2-Slide Top, 3-Slide Right, 4-Slide Bottom, 5-Slide Left, 6-Carousel Right, 7-Carousel Left
transition_speed: 1400,
// Speed of transition
// Components
slide_links: 'blank',
// Individual links for each slide (Options: false, 'num', 'name', 'blank')
slides: [
// Slideshow Images
{
image: 'http://www.hotel-zur-traube.eu/wp-content/themes/hotelzurtraube/images/bg.jpg',
title: 'Hotel-Pension-Restaurant Zur Traube in Altenahr'
}, {
image: 'http://www.hotel-zur-traube.eu/wp-content/themes/hotelzurtraube/images/bg2.jpg',
title: 'Hotel-Pension-Restaurant Zur Traube in Altenahr'
}, {
image: 'http://www.hotel-zur-traube.eu/wp-content/themes/hotelzurtraube/images/bg3.jpg',
title: 'Hotel-Pension-Restaurant Zur Traube in Altenahr'
}
]
});
});
</script>");
} ?>
<?php if(is_page(array('Restaurant'))) { ?>
<script type="text/javascript">
jQuery(function($) {
$.supersized({
// Functionality
slide_interval: 9000,
// Length between transitions
transition: 1,
// 0-None, 1-Fade, 2-Slide Top, 3-Slide Right, 4-Slide Bottom, 5-Slide Left, 6-Carousel Right, 7-Carousel Left
transition_speed: 1400,
// Speed of transition
// Components
slide_links: 'blank',
// Individual links for each slide (Options: false, 'num', 'name', 'blank')
slides: [
// Slideshow Images
{
image: 'http://www.hotel-zur-traube.eu/wp-content/themes/hotelzurtraube/images/bg.jpg',
title: 'Hotel-Pension-Restaurant Zur Traube in Altenahr'
}, {
image: 'http://www.hotel-zur-traube.eu/wp-content/themes/hotelzurtraube/images/bg2.jpg',
title: 'Hotel-Pension-Restaurant Zur Traube in Altenahr'
}, {
image: 'http://www.hotel-zur-traube.eu/wp-content/themes/hotelzurtraube/images/bg3.jpg',
title: 'Hotel-Pension-Restaurant Zur Traube in Altenahr'
}
]
});
});
</script>
<? } ?>
<?php if(is_page(array('Restaurant'))) { ?>
<script type="text/javascript">
jQuery(function($) {
$.supersized({
slide_interval: 9000,
transition: 1,
transition_speed: 1400,
slide_links: 'blank',
slides: [
{
image: 'http://www.hotel-zur-traube.eu/wp-content/themes/hotelzurtraube/images/bg.jpg',
title: 'Hotel-Pension-Restaurant Zur Traube in Altenahr'
}, {
image: 'http://www.hotel-zur-traube.eu/wp-content/themes/hotelzurtraube/images/bg2.jpg',
title: 'Hotel-Pension-Restaurant Zur Traube in Altenahr'
}, {
image: 'http://www.hotel-zur-traube.eu/wp-content/themes/hotelzurtraube/images/bg3.jpg',
title: 'Hotel-Pension-Restaurant Zur Traube in Altenahr'
}
]
});
});
</script>
<? } ?>
jQuery(函数($){
美元。超大({
滑动间隔:9000,
过渡:1,
过渡速度:1400,
幻灯片链接:“空白”,
幻灯片:[
{
图像:'http://www.hotel-zur-traube.eu/wp-content/themes/hotelzurtraube/images/bg.jpg',
标题:“阿尔特纳尔祖尔特劳伯养老金餐厅酒店”
}, {
图像:'http://www.hotel-zur-traube.eu/wp-content/themes/hotelzurtraube/images/bg2.jpg',
标题:“阿尔特纳尔祖尔特劳伯养老金餐厅酒店”
}, {
图像:'http://www.hotel-zur-traube.eu/wp-content/themes/hotelzurtraube/images/bg3.jpg',
标题:“阿尔特纳尔祖尔特劳伯养老金餐厅酒店”
}
]
});
});
您是否检查了控制台以查看有哪些JS错误?您正在引号中使用引号。。。所以您有一个PHP错误。由于您可能关闭了错误报告功能,因此会得到一个空白页。这也解决了问题,但它发生的原因没有得到解决,也没有指出很多原因!但是,如果我想使用else语句,我是否需要再次回音?使用此方法,他会注意到引号问题,因此这是一个很好的解决方案,可以避免此问题。以下是完整的语法://processing//processing
@Dupuis-David-它解决了问题,但纯属运气,这表明echo语法是错误的,但实际上它没有问题——我发现在某些情况下它更可读,所以这是个人的选择