2

我正在努力将 jPlayer 整合到我们的 WordPress 网站中。我并不特别关心可用的两个插件,因为我们的客户在技术上有点不足。我们希望完成的是将标题和 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>
4

1 回答 1

0

您正在尝试使用 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() 重新设置帖子数据的要点。

于 2012-10-07T20:22:16.867 回答