当我单身的时候。php页面中,我显示了第一个图像附件。然后,我想加载下一个(和上一个)图像附件,而无需重新加载页面。
所以在单曲中。php我从这里开始检索带有图像html的数组:
<?php $args = array(\'post_type\' => \'attachment\', \'post_mime_type\' => \'image\', \'order\'=> \'ASC\', \'numberposts\' => -1, \'post_status\' => null, \'post_parent\' => $post->ID );
$attachments = get_posts($args);
if ($attachments) {
foreach ( $attachments as $attachment ) {
$my_image = wp_get_attachment_image($attachment->ID, large) );
$attachments_list[] = $my_image;
}
}
reset($attachments_list);
$first_image = current($attachments_list);
echo $first_image;
?>
然后在脚本中。js文件我想获取我的php数组$attachments\\u列表的值,以便执行以下操作:$(document).ready(function(){
var count = attachments_list.lenght();
var init = 0;
var current = init;
if (count > 1) {
$(\'#next-img\').click(function() {
if (current+1 < count) {
current++
} else if (current+1 === count) {
current = init;
}
$(\'#image-container\').html(attachments_list[current]);
});
$(\'#previous-img\').click(function() {
if (current > init) {
current--
} else if (current === init) {
current = count-1;
}
$(\'#image-container\').html(attachments_list[current]);
});
}
});
如何在脚本中检索php$attachments\\u list数组到attachments\\u list的值。js文件?可能是Json?感谢您的关注