Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * Random player with automatic insertion
- * Install : append the code after the_content()
- * Description : Grabs all audio files attached to the post and prints the Audio Player
- * Dependencies : Plugin Audio Player http://wordpress.org/extend/plugins/audio-player/
- * Observations : this code will be better if converted to a function
- */
- the_content();
- // 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 );
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement