[Plugin: Audio Player] Random player with automatic insertion
-
this code will insert a random playlist with all the audio files attached to a page
i’m using it in a template page inserting this code after the_content
<?php the_content(); ?> <?php // QUERY $audios =& get_children( 'post_parent='.$post->ID.'&post_type=attachment&post_mime_type=audio' ); // IF HAVE ATTACHED AUDIOS AND AVAILABLE FUNCTION if ( !empty($audios) && function_exists("insert_audio_player")) { // BASIC VARS $echou_ini = "[audio:"; $echou_aud = ""; $echou_tit = "|titles="; $echou_end = "|autostart=yes]"; $counter = 0; $a = array(); // GRAB VALUES AND MAKE TEMP ARRAY foreach ( $audios as $attachment_id => $attachment ) { $a[$counter]['url'] = wp_get_attachment_url( $attachment_id ); $post_id_7 = get_post($attachment_id); $a[$counter]['tit'] = $post_id_7->post_title; $counter++; } // SHUFFLE TEMP ARRAY AND PREPARE AUX STRINGS shuffle($a); foreach ( $a as $audio ) { $echou_aud .= $audio['url']. ","; $echou_tit .= $audio['tit'].","; } // REMOVE EXTRA COMMA $echou_aud_new = substr($echou_aud, 0, -1); $echou_tit_new = substr($echou_tit, 0, -1); // MAIN STRING $echou_final = $echou_ini . $echou_aud_new . $echou_tit_new . $echou_end; // PRINT TEST STRING (REMOVE AFTER TEST) echo $echou_final; // INSERT PLAYER insert_audio_player( $echou_final ); } ?>
Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
- The topic ‘[Plugin: Audio Player] Random player with automatic insertion’ is closed to new replies.