0

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. Any help would be appreciated. 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>
2
  • 2
    Please do not build JSON like that. Use json_encode(). Commented Sep 18, 2012 at 22:04
  • What is json_encode()? Commented Sep 18, 2012 at 22:40

1 Answer 1

1

Don't output javascript inline mixed with php. enqueue a single script and pass post-specific data to it via wp_localize_script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.