Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*** 1) Dans le functions.php du thème actif ***/
- /* d'abord on charge thickbox si on est sur la page listant les photos du membre */
- function thomas_load_thickbox() {
- wp_enqueue_style('thickbox');
- wp_enqueue_script('jquery');
- wp_enqueue_script('thickbox');
- // on ajoute un hook à wp_footer dés maintenant car on est sûr d'être sur le bon screen
- add_action('wp_footer', 'thomas_override_bp_album');
- }
- add_action('bp_album_screen_pictures', 'thomas_load_thickbox');
- /* ici on va ajouter un champ de test car BuddyPress Album ne référence pas les IDs des photos dans le template */
- function thomas_build_pattern( $pattern ){
- $extension = explode( ".", $pattern );
- $indice_ext = count( $extension ) - 1;
- $nbcar_ext = strlen( $extension[$indice_ext] ) + 1;
- return substr( $pattern,0, strlen( $pattern ) - $nbcar_ext );
- }
- /* comme on a pas de hook, on surcharge le client ! */
- function thomas_override_bp_album() {
- global $pictures_template;
- $json_pics = array();
- foreach( $pictures_template->pictures as $pics ) {
- //en mettant un attribut rel="diapo" juste après la class thickbox, on peut même faire un diaporama
- $json_pics[]= array( 'pattern' => thomas_build_pattern( $pics->pic_org_url ), 'html' => '<a href="'.site_url( $pics->pic_org_url ).'" class="thickbox">Zoom</a>' );
- }
- $json_pics = json_encode($json_pics);
- ?>
- <script type="text/javascript">
- var jsonpics = <?php echo $json_pics;?>
- function goodHtml( search ){
- var trouver = -1;
- for( i=0; i < jsonpics.length; i++ ){
- if( search.indexOf( jsonpics[i]['pattern'] ) !=-1 )
- trouver = jsonpics[i]['html'];
- }
- return trouver;
- }
- jQuery('document').ready(function($){
- $('.picture-thumb-box').each(function(){
- test = goodHtml( $(this).find('.picture-thumb img').attr('src') );
- if( test != -1 )
- $(this).append(test);
- });
- });
- </script>
- <?php
- }
- /*** 2) Dans le footer.php du thème actif juste au-dessus de la function wp_footer() ***/
- ?>
- <script type="text/javascript">
- if ( typeof tb_pathToImage != 'string' )
- {
- var tb_pathToImage = "<?php echo site_url('/wp-includes/js/thickbox/loadingAnimation.gif');?>";
- }
- if ( typeof tb_closeImage != 'string' )
- {
- var tb_closeImage = "<?php echo site_url('/wp-includes/js/thickbox/tb-close.png');?>";
- }
- </script>
- <?php
- /*** et voilà ! ***/
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement