Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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>
share|improve this question
2  
Please do not build JSON like that. Use json_encode(). –  ThiefMaster Sep 18 '12 at 22:04
    
What is json_encode()? –  David Deuster Sep 18 '12 at 22:40
add comment

1 Answer

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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