Open lightbox instead of media's permalink


#1

Hello, I have added the code below to show last N images in member’s header, but when I click on a thumbnail it takes me to the user’s media’s permalink instead of displaying the lightbox.

How can I display the lightbox ?

Thanks a lot, Marine

add_action( 'bp_after_member_header', 'show_last_n_images', 99 );
function show_last_n_images() {
$n = 5;
if( $user_id = bp_displayed_user_id() ) {
$model = new RTMediaModel();
$results = $model->get( array( 'media_type' => 'photo', 'media_author' => $user_id ), 0, $n );
if( $results ) {?>
<ul>
<?php foreach( $results as $image ) { ?>
<li>
<div class="rtmedia-media" id="rtmedia-media-<?php echo $image->id; ?>">
<a href="<?php echo get_rtmedia_permalink( $image->id ); ?>" title="<?php echo $image->media_title; ?>">
<img src="<?php rtmedia_image( "rt_media_thumbnail", $image->id ); ?>" alt="<?php echo rtmedia_image_alt( $image->id );?>" />
</a>
</div>
</li>
<?php } ?>
</ul>
<?php
}
 }
}

#2

@marineb in order to open images in popup. you will have to follow the same HTML for media item list. check the below code and let me know if it work for you

add_action( 'bp_after_member_header', 'show_last_n_images', 99 );
function show_last_n_images() {
	$n = 5;
	if( $user_id = bp_displayed_user_id() ) {
		$model = new RTMediaModel();
		$results = $model->get( array( 'media_type' => 'photo', 'media_author' => $user_id ), 0, $n );
		// print_r($results);
		if( $results ) {?>
		<div class='rtmedia-activity-container'>
			<ul class='rtmedia-list masonry'>
				<?php foreach( $results as $image ) { 
					?>
					<li class='rtmedia-list-item masonry-brick' id='<?php echo $image->id; ?>'>
						<div class="rtmedia-media" id="rtmedia-media-<?php echo $image->id; ?>">
							<a href="<?php echo get_rtmedia_permalink( $image->id ); ?>" title="<?php echo $image->media_title; ?>">
							<img src="<?php rtmedia_image( "rt_media_thumbnail", $image->id ); ?>" alt="<?php echo rtmedia_image_alt( $image->id );?>" />
							</a>
						</div>
					</li>
					<?php
				 } ?>
			</ul>
		</div>
	<?php
		}
	}	
}

#3

Thanks a lot naveengiri, with this code it works perfect now !


#4

Hello @marineb,

We are glad to know that your issue has been fixed.

We are closing this topic now. Feel free to create new if you have any doubts.

Thank you.


#5