2

我已经为此苦苦挣扎了一段时间,非常感谢一些帮助!

我正在尝试在 Wordpress 媒体库中使用 2 个 codexes 填充 html5 音频播放器。

我正在使用 wp 函数 get_posts 并为 post_mime_types 'ogg' 创建了一个过滤器。我已经在 get_posts 的 $args 中设置了 post_mime_type 的参数。现在我想循环并将它们分类到音频播放器列表中,如 $mp3 和 $ogg。

    $ogg = wp_get_attachment_url( $audio_attachment->post_mime_type="application/ogg" );

...在下面的代码中但不输出任何内容:

        <?php
         $query_audio_args = array(
           'post_type' => 'attachment',
           'post_mime_type' =>'application/ogg,audio',
           'post_status' => 'inherit',
           'posts_per_page' => -1,
      );

      $audio_attachments = get_posts($query_audio_args);
            foreach ( $audio_attachments as $audio_attachment ) {
                // Trying to sort them into $ogg, $aif and $mp3
                $ogg = wp_get_attachment_url( $audio_attachment->ID);

                $mp3 = wp_get_attachment_url( $audio_attachment-ID);

                $tracks[] = '{
                    title:"'.$audio_attachment->post_title.'",
                    mp3:"'.$mp3.'",
                    oga:"'.$ogg.'",
                    aif:"'.$aif.'"
                }';
                $alltracks = implode(',',$tracks);
            }
    ?>  

编辑:我也试过这个,目的是创建一个多数组,但在访问这些值时遇到了困难:

            <?php
$query_audio_args = array(
           'post_type' => 'attachment',
           'post_mime_type' =>'application/ogg',
           'post_status' => 'inherit',
           'posts_per_page' => -1,
      );                

      $audio_attachments = get_posts($query_audio_args);
        $ogg = array();
            foreach ( $audio_attachments as $uk => $uv ) {                  
             $ogg[] = $uv->guid;                            
            }
         $query_audio_args1 = array(
           'post_type' => 'attachment',
           'post_mime_type' =>'audio',
           'post_status' => 'inherit',
           'posts_per_page' => -1,
      );                

     $audio_attachments1 = get_posts($query_audio_args1);
        $mp3 = array();
            foreach ( $audio_attachments1 as $ak => $av ) {                     
                $mp3[] = $av->guid;             
            }

        $audio = array(
                $ogg,
                $mp3
        );
        print_r($audio);
        foreach($audio as $k =>$v)
                    $tracks[] = '{
                        title:"'.$uv->post_title.'",
                        mp3:"'.$mp3->guid.'",
                        oga:"'.$uv->guid.'",
                        aif:"'.$aifv->guid.'"
                    }';
            $alltracks = implode(',',$tracks);                          
    ?>
4

0 回答 0