i have an edited Supersized...i've added a code for loop about photos on wp....
我有一个编辑过的超级...我已经添加了关于wp上的照片循环的代码....
so i've this on original:
所以我原来的这个:
slides : [
{image : 'http://buildinternet.s3.amazonaws.com/projects/supersized/3.2/slides/shaden-2.jpg', title : 'Image Credit: *e Shaden', thumb : 'http://buildinternet.s3.amazonaws.com/projects/supersized/3.2/thumbs/shaden-2.jpg', url : 'http://www.nonsensesociety.com/2011/06/*e-shaden/'},
{image : 'http://buildinternet.s3.amazonaws.com/projects/supersized/3.2/slides/shaden-3.jpg', title : 'Image Credit: *e Shaden', thumb : 'http://buildinternet.s3.amazonaws.com/projects/supersized/3.2/thumbs/shaden-3.jpg', url : 'http://www.nonsensesociety.com/2011/06/*e-shaden/'}
],
and i have edited for loop gallery from wp:
我已经从wp编辑了循环库:
slides : [
<?php query_posts('cat=46'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php
$thumb = get_post_meta($post->ID,'_thumbnail_id',false);
$thumb = wp_get_attachment_image_src($thumb[0], false);
$thumb = $thumb[0];
if ( has_post_thumbnail() ) { ?>
{image : '<?php echo $thumb; ?>'},
<?php } ?>
<?php endwhile; else: ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
],
and it work on Chrome, Firefox etc...
它适用于Chrome,Firefox等...
but i've a problem with this alert on IE 8 - 7 and Firefox old:
但我对IE 8 - 7和Firefox旧版本的此警报存在问题:
Message: ‘slides[...].url’ is null or not an object
消息:'slides [...]。url'为null或不是对象
Line: 23
行:23
Char: 3
查尔:3
Code: 0
代码:0
URI: supersized.3.0.js
URI:supersized.3.0.js
i've heard that the true problem is a last comma (you can see at the first code on this post, there isn't...and it work perfectly.
我听说真正的问题是最后一个逗号(你可以在这篇文章的第一段代码中看到,没有......而且它完美无缺。
so i want to resolve for remove the last comma at the edited slides...'cause it repeat comme at one by one images and it cause this problem on ie... how can i remove this last comma?
所以我想解决删除编辑幻灯片上的最后一个逗号...'因为它在一个接一个的图像重复纪念,它导致这个问题,即...我怎么能删除这最后一个逗号?
5 个解决方案
#1
1
Why are you constantly dropping in and out of PHP? That's terribly inefficient...
你为什么不断进出PHP?这非常低效......
slides : [
<?php
query_posts('cat=46');
if ( have_posts() ) {
$post_array = Array();
while ( have_posts() ) {
the_post();
$thumb = get_post_meta($post->ID,'_thumbnail_id',false);
$thumb = wp_get_attachment_image_src($thumb[0], false);
$thumb = $thumb[0];
if ( has_post_thumbnail() ) {
$post_array[] = "{image : '".$thumb."'}";
}
}
echo implode(",",$post_array);
}
wp_reset_query();
?>
],
#2
0
Are you sure the problem is about the last coma? If yes you need to save all the images in a variable, get rid of the last coma at the end of the loop and the print the result:
你确定问题是关于最后一次昏迷吗?如果是,则需要将所有图像保存在变量中,摆脱循环结束时的最后一个昏迷并打印结果:
<?php $string = ''; ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php
$thumb = get_post_meta($post->ID,'_thumbnail_id',false);
$thumb = wp_get_attachment_image_src($thumb[0], false);
$thumb = $thumb[0];
if ( has_post_thumbnail() ) { ?>
<?php $string.= '{image : '.$thumb.'},';
<?php } ?>
<?php endwhile; ?>
<?php echo substr($string, -1); ?>
#3
0
3 solutions:
3解决方案:
one:
一:
<?php if ( have_posts() ) : $i=0; while ( have_posts() ) : the_post(); ?>
<?php
$thumb = get_post_meta($post->ID,'_thumbnail_id',false);
$thumb = wp_get_attachment_image_src($thumb[0], false);
$thumb = $thumb[0];
if ( has_post_thumbnail() ) { ?>
<?=($i>0?',':'')?>{image : '<?php echo $thumb; ?>'}
<?php } $i++;?>
two:
二:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php
$thumb = get_post_meta($post->ID,'_thumbnail_id',false);
$thumb = wp_get_attachment_image_src($thumb[0], false);
$thumb = $thumb[0];
if ( has_post_thumbnail() ) { ?>
$string[]="{image : '<?php echo $thumb; ?>'}";
<?php } if (!empty($string)) implode(",",$string);
tree:
树:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php
$thumb = get_post_meta($post->ID,'_thumbnail_id',false);
$thumb = wp_get_attachment_image_src($thumb[0], false);
$thumb = $thumb[0];
if ( has_post_thumbnail() ) { ?>
$string.="{image : '<?php echo $thumb; ?>'}";
<?php } $lenght=strlen($string)-2;
echo substr($string,0,$lenght);
For my point of view the second solution is the most clean.
对于我的观点,第二种解决方案是最干净的。
#4
0
Why not use json
to form the slides array
为什么不使用json来形成幻灯片数组
<?php
$slide_arr = array ();
query_posts('cat=46');
if ( have_posts() ) :
while ( have_posts() ) : the_post();
$thumb = get_post_meta($post->ID,'_thumbnail_id',false);
$thumb = wp_get_attachment_image_src($thumb[0], false);
$thumb = $thumb[0];
if ( has_post_thumbnail() ) {
$slideObj = new stdClass;
$slideObj->image = $thumb;
$slide_arr[] = $slideObj;
}
endwhile;
else:
endif;
wp_reset_query();
$slide_json = json_encode($slide_arr);
?>
var slide_json = '<?php echo $slide_json; ?>';
var slide_arr = eval('(' + slide_json + ')');
// js code ...
slides : slide_arr,
#5
-2
it is valid to have a trailing comma in an array of JS objects, so the comma is not your issue. This error is thrown because you have not set the URL property for your slide objects. this is your JSON string that you currently output:
在JS对象数组中使用尾随逗号是有效的,因此逗号不是您的问题。抛出此错误是因为您尚未设置幻灯片对象的URL属性。这是您当前输出的JSON字符串:
{image : 'http://buildinternet.s3.amazonaws.com/projects/supersized/3.2/slides/shaden-2.jpg'}
but you need the complete object for slides like this:
但你需要像这样的幻灯片的完整对象:
{image : 'http://buildinternet.s3.amazonaws.com/projects/supersized/3.2/slides/shaden-2.jpg', title: 'YOUR TITLE HERE', thumb: 'SOME IMAGE PATH GOES HERE', url: 'SOME URL PATH GOES HERE'}
UPDATE:
更新:
People seem to think there is some sort of problem wit the comma. I do not think this is the main issue. It might cause problems (i dont think it will) but besides that, this guys code WILL NEVER WORK WITHOUT THROWING THE ERROR THAT HE NOTED IN HIS QUESTION. I went directly to the supersize source to show you people what the problem is.
人们似乎认为逗号存在某种问题。我不认为这是主要问题。它可能会导致问题(我不认为会这样)但除此之外,这些人的代码将永远无法解决他在他的问题中注意到的错误。我直接去了超大尺寸的来源,向你展示人们的问题所在。
var imageLink = (options.slides[options.slides.length - 1].url) ? "href='" + options.slides[options.slides.length - 1].url + "'" : "";
there it is. on line 23, just as HIS ERROR MESSAGE SAYS. The script is trying to access the URL property of each slide object. BUT HE HASN'T SET A URL PROPERTY. so it will ALWAYS throw the error that THE USER SAID HE IS GETTING.
它就是。在第23行,正如他的错误消息所说。该脚本正在尝试访问每个幻灯片对象的URL属性。但他没有设置URL属性。所以它总是会抛出用户认为他正在获取的错误。
#1
1
Why are you constantly dropping in and out of PHP? That's terribly inefficient...
你为什么不断进出PHP?这非常低效......
slides : [
<?php
query_posts('cat=46');
if ( have_posts() ) {
$post_array = Array();
while ( have_posts() ) {
the_post();
$thumb = get_post_meta($post->ID,'_thumbnail_id',false);
$thumb = wp_get_attachment_image_src($thumb[0], false);
$thumb = $thumb[0];
if ( has_post_thumbnail() ) {
$post_array[] = "{image : '".$thumb."'}";
}
}
echo implode(",",$post_array);
}
wp_reset_query();
?>
],
#2
0
Are you sure the problem is about the last coma? If yes you need to save all the images in a variable, get rid of the last coma at the end of the loop and the print the result:
你确定问题是关于最后一次昏迷吗?如果是,则需要将所有图像保存在变量中,摆脱循环结束时的最后一个昏迷并打印结果:
<?php $string = ''; ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php
$thumb = get_post_meta($post->ID,'_thumbnail_id',false);
$thumb = wp_get_attachment_image_src($thumb[0], false);
$thumb = $thumb[0];
if ( has_post_thumbnail() ) { ?>
<?php $string.= '{image : '.$thumb.'},';
<?php } ?>
<?php endwhile; ?>
<?php echo substr($string, -1); ?>
#3
0
3 solutions:
3解决方案:
one:
一:
<?php if ( have_posts() ) : $i=0; while ( have_posts() ) : the_post(); ?>
<?php
$thumb = get_post_meta($post->ID,'_thumbnail_id',false);
$thumb = wp_get_attachment_image_src($thumb[0], false);
$thumb = $thumb[0];
if ( has_post_thumbnail() ) { ?>
<?=($i>0?',':'')?>{image : '<?php echo $thumb; ?>'}
<?php } $i++;?>
two:
二:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php
$thumb = get_post_meta($post->ID,'_thumbnail_id',false);
$thumb = wp_get_attachment_image_src($thumb[0], false);
$thumb = $thumb[0];
if ( has_post_thumbnail() ) { ?>
$string[]="{image : '<?php echo $thumb; ?>'}";
<?php } if (!empty($string)) implode(",",$string);
tree:
树:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php
$thumb = get_post_meta($post->ID,'_thumbnail_id',false);
$thumb = wp_get_attachment_image_src($thumb[0], false);
$thumb = $thumb[0];
if ( has_post_thumbnail() ) { ?>
$string.="{image : '<?php echo $thumb; ?>'}";
<?php } $lenght=strlen($string)-2;
echo substr($string,0,$lenght);
For my point of view the second solution is the most clean.
对于我的观点,第二种解决方案是最干净的。
#4
0
Why not use json
to form the slides array
为什么不使用json来形成幻灯片数组
<?php
$slide_arr = array ();
query_posts('cat=46');
if ( have_posts() ) :
while ( have_posts() ) : the_post();
$thumb = get_post_meta($post->ID,'_thumbnail_id',false);
$thumb = wp_get_attachment_image_src($thumb[0], false);
$thumb = $thumb[0];
if ( has_post_thumbnail() ) {
$slideObj = new stdClass;
$slideObj->image = $thumb;
$slide_arr[] = $slideObj;
}
endwhile;
else:
endif;
wp_reset_query();
$slide_json = json_encode($slide_arr);
?>
var slide_json = '<?php echo $slide_json; ?>';
var slide_arr = eval('(' + slide_json + ')');
// js code ...
slides : slide_arr,
#5
-2
it is valid to have a trailing comma in an array of JS objects, so the comma is not your issue. This error is thrown because you have not set the URL property for your slide objects. this is your JSON string that you currently output:
在JS对象数组中使用尾随逗号是有效的,因此逗号不是您的问题。抛出此错误是因为您尚未设置幻灯片对象的URL属性。这是您当前输出的JSON字符串:
{image : 'http://buildinternet.s3.amazonaws.com/projects/supersized/3.2/slides/shaden-2.jpg'}
but you need the complete object for slides like this:
但你需要像这样的幻灯片的完整对象:
{image : 'http://buildinternet.s3.amazonaws.com/projects/supersized/3.2/slides/shaden-2.jpg', title: 'YOUR TITLE HERE', thumb: 'SOME IMAGE PATH GOES HERE', url: 'SOME URL PATH GOES HERE'}
UPDATE:
更新:
People seem to think there is some sort of problem wit the comma. I do not think this is the main issue. It might cause problems (i dont think it will) but besides that, this guys code WILL NEVER WORK WITHOUT THROWING THE ERROR THAT HE NOTED IN HIS QUESTION. I went directly to the supersize source to show you people what the problem is.
人们似乎认为逗号存在某种问题。我不认为这是主要问题。它可能会导致问题(我不认为会这样)但除此之外,这些人的代码将永远无法解决他在他的问题中注意到的错误。我直接去了超大尺寸的来源,向你展示人们的问题所在。
var imageLink = (options.slides[options.slides.length - 1].url) ? "href='" + options.slides[options.slides.length - 1].url + "'" : "";
there it is. on line 23, just as HIS ERROR MESSAGE SAYS. The script is trying to access the URL property of each slide object. BUT HE HASN'T SET A URL PROPERTY. so it will ALWAYS throw the error that THE USER SAID HE IS GETTING.
它就是。在第23行,正如他的错误消息所说。该脚本正在尝试访问每个幻灯片对象的URL属性。但他没有设置URL属性。所以它总是会抛出用户认为他正在获取的错误。