Utilisez PowerPress dans vos thèmes WordPress
Bonne nouvelle! Cette fonction sera incluse dans les prochaines versions de PowerPress sous le nom de powerpress_the_players().
Même si PowerPress, l’excellent gestionnaire de podcasts pour WordPress, offre la fonction the_powerpress_content() pour placer un lecteur à l’intérieur d’un thème, celle-ci fonctionne seulement à l’intérieur du Loop de WordPress.
¿Que pasa?
Derrière le rideau, cette fonction recherche les informations de podcasts à l’intérieur de l’article sur lequel le Loop est positionné. Si vous placez cette fonction dans l’en-tête d’une page, le Loop est placé sur le premier article et le lecteur ne s’affichera pas si celui-ci ne contient pas de podcast.
Comment régler ce problème
La fonction get_player() ci-dessous va chercher le premier article dans le Loop à contenir les custom keys utilisées par PowerPress. Pour l’utiliser, copiez simplement le code ci-dessous à l’intérieur de votre fichier functions.php.
function create_player(){
//Use this function to insert the Powerpress player anywhere in the page.
//Made by Nicolas Bouliane (http://nicolasbouliane.com/)
/*We're going to use the Loop to retrieve the latest post with the 'enclosure' custom key set
//then interpret it and manually launch powerpressplayer_build with the URL contained within
//that data.*/
//Let's reset the Loop to make sure we look through all posts
rewind_posts();
//Loop through each post
while (have_posts()) : the_post();
//Check if there are custom keys for this post
if( get_post_custom($post->ID)){
//Check the record for the 'enclosure' key
$meta = get_post_custom($post->ID);
if(isset($meta['enclosure'][0])){
//Split it as to retrieve what matters most: the file URL which should be on the
//first line (I didn't test much)
$url = split("n",$meta['enclosure'][0],2);
$url = $url[0];
//Create a player and end the loop. That was easy!
$Settings = get_option('powerpress_general');
echo(powerpressplayer_build( $url, $Settings, $ExtraData ));
break;
}
}
endwhile;
/*Reset the loop again in case this code ends up in the header. Otherwise, the posts would
//start from the first podcast that was found.*/
rewind_posts();
}
Voilà, c’est réglé! Si vous avez besoin de services plus poussés sur votre blog WordPress, n’hésitez pas à me contacter.
Commentaires