I’m working on incorporating the jPlayer into our WordPress site. I don’t particularly care for the two plugins that are available as our client is a bit on the technically deficient side. What we are looking to accomplish is have the Title and Mp3 load into the JavaScript for the jPlayer playlist. Currently everything is loading just fine and returning the appropriate texts, however I’m unable to get the File Name and the Attachment URL to load appropriately. I’m fairly new to java and wordpress for that matter. If you would like to see a live site example, please visit 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>
You are attempting to use the var $attachment to access your attachments data. But you don’t ever set your $attachment var to actually contain any data, so its currently empty. As you have set up your post data within your loop using $loop->the_post(); you should be able to;
http://codex.wordpress.org/Class_Reference/WP_Query
Take note of the point about re setting your post data using wp_reset_postdata().