我在ie8工作时遇到了问题,我发现最后一个逗号是问题,但不知道如何解决。
这是当前代码。
<?php $args = array( \'post_type\' => \'katalog\', \'posts_per_page\' => 999 );
$loop = new WP_Query( $args );
if ($loop->have_posts()) :
while ($loop->have_posts()) : $loop->the_post(); ?>
<?php global $post; $thumb=wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), \'full\'); $thumb2=wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), \'medium\'); $url = rwmb_meta( \'smb_katalozi\' ); ?>
{image : "<?php echo $thumb[0] ?> ", title : "<?php echo get_the_title() ?>", url : "<?php echo post_permalink( $url ); ?>"},
<?php endwhile; else: endif; ?>
输出是这样的
{image : "img url", title : "title", url : "url"},
{image : "img url", title : "title", url : "url"},
我希望是这样
{image : "img url", title : "title", url : "url"},
{image : "img url", title : "title", url : "url"}
所以,就最后一个逗号而言,它是不同的。
将其与此代码配合使用
<?php
$args = array( \'post_type\' => \'katalog\', \'posts_per_page\' => 999 );
$loop = new WP_Query( $args );
$post_count = 0;
$te = $loop->post_count;
$total = $te-1;
if ($loop->have_posts()) :
while ($loop->have_posts()) : $loop->the_post();
global $post; $thumb=wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), \'full\'); $thumb2=wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), \'medium\'); $url = rwmb_meta( \'smb_katalozi\' );
if ($post_count == 0 || $post_count !== $total) { ?>
{image : "<?php echo $thumb[0] ?> ", title : "<?php echo get_the_title() ?>", url : "<?php echo post_permalink( $url ); ?>"},
<?php } if ($post_count == $total) { ?>
{image : "<?php echo $thumb[0] ?> ", title : "<?php echo get_the_title() ?>", url : "<?php echo post_permalink( $url ); ?>"}
<?php }
$post_count++;
endwhile; else: endif;
?>