Support » Fixing WordPress » Load Attachments into JavaScript

  • I’ve been working on a custom jPlayer for our theme. Right now I’m going through the process of integrating the script to load in the mp3 files and would like to do that via files that are attached to the post. I’m using the post_mine_type to filter out those files. Below is the code I’m working on to loop through the various attachments in the JavaScript that loads them.

    I’m having some difficulty getting them to load and to loop properly. Any help would be greatly appreciated. I’m sure its something minor that I’m missing.

    <!--Begin Jplayer Playlist -->
    		<script type="text/javascript">
    			new jPlayerPlaylist({
    				jPlayer: "#jquery_jplayer_1",
    				cssSelectorAncestor: "#jp_container_1"
    			}, [
    			<!--This is what needs to loop -->
            		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 );
            		<?php if ($the_jukebox_query->have_posts()) : ?>
    						title:<?php echo apply_filters( 'the_title', $attachment->post_title ); ?>,
    						mp3:<?php wp_get_attachment_link( $attachment->ID, false ); ?>,
    				<?php endif; ?>
    			<!--This would be the end of the loop -->
    			], {
    				swfPath: "<?php echo get_template_directory_uri(); ?>/js",
    				supplied: "mp3",
    				wmode: "window"
    <!--End Jplayer Playlist -->
  • The topic ‘Load Attachments into JavaScript’ is closed to new replies.