我正在将jPlayer整合到我们的WordPress网站中。我不太在乎这两个可用的插件,因为我们的客户端在技术上有些不足。我们希望完成的工作是将Title和Mp3加载到jPlayer播放列表的JavaScript中。当前,一切都可以正常加载并返回适当的文本,但是我无法获取文件名称和附件URL来进行适当的加载。对于这个问题,我对java和wordpress还是陌生的。如果您想查看现场示例,请访问http://www.ourgoodfight.com/?p=6054
<!--Begin Jplayer Playlist -->
<script type="text/javascript">
//<![CDATA[
$(document).ready(function(){
new jPlayerPlaylist({
jPlayer: "#jquery_jplayer_1",
cssSelectorAncestor: "#jp_container_1"
}, [
<?php
global $post;
$jukebox_args = get_posts( array(
'post_type' => 'attachment',
'posts_per_page' => -1,
'post_mime_type' => 'audio/mpeg',
'orderby' => 'menu_order',
'order' => 'ASC',
'post_parent' => $post->ID
));
$the_jukebox_query = new WP_Query( $jukebox_args );
?>
<!--This is what needs to loop -->
<?php
$loop = new WP_Query( $jukebox_args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
{
title:<?php echo apply_filters( 'the_title', $attachment->post_title ); ?>,
mp3:<?php echo wp_get_attachment_url( $attachment->ID, false ); ?>,
},
<?php endwhile;?>
<!--This would be the end of the loop -->
], {
swfPath: "<?php echo get_template_directory_uri(); ?>/js",
supplied: "mp3",
wmode: "window"
});
});
//]]>
</script>
您正在尝试使用var $ attachment访问附件数据。但是您永远不会将$ attachment var设置为实际上包含任何数据,因此其当前为空。使用$ loop-> the_post();在循环中设置发布数据后,您应该能够;
title:<?php echo apply_filters( 'the_title', get_the_title() ); ?>,
mp3:<?php echo wp_get_attachment_url( get_the_ID(), false ); ?>,
http://codex.wordpress.org/Class_Reference/WP_Query
注意有关使用wp_reset_postdata()重新设置您的帖子数据的要点。