Template Tags

Here's a quick example to make the player move to the sidebar on the posts index page and play 5 random tracks from your library

Put this in index.php before the posts loop starts:

<?php if ( function_exists('mp3j_flag') ) { mp3j_flag(); } ?>


Put this in sidebar.php somewhere below the opening div (note this is very simplistic code, you'll need at least 5 tracks in your library for it to work):

<?php 
if ( function_exists( 'mp3j_grab_library' ) ) { 
    $lib = mp3j_grab_library();
    $files = $lib['filenames'];
    shuffle( $files );
    $files = array_slice( $files, 0, 5 );
    mp3j_set_meta( $files );
    mp3j_put( 'feed' );
}   
?>


Finally, to set the smaller player stylesheet for the posts index only, put this in header.php above wp_head():

<?php 
if ( function_exists('mp3j_addscripts') ) { 
    if ( is_home() ) {
        mp3j_addscripts('/wp-content/plugins/mp3-jplayer/css/mp3jplayer-blu-sidebar.css'); 
    }
}
?>


Tag Details

Note: there's an admin option to ignore the tags which needs to remain unticked when you want to use them!

mp3j_addscripts( $style )


mp3j_flag( $set )


mp3j_grab_library( $format )


mp3j_set_meta( $tracks, $captions )


mp3j_put( $mode, $position, $dload, $autoplay, $playlist )


mp3j_debug($info)



ALWAYS use function_exists() to make sure the tags are available before running them, eg:

<?php if ( function_exists('mp3j_addscripts') ) { mp3j_addscripts('styleD'); } ?>

If you ever disable the plugin, running the tags in your theme without checking first will break your pages.