Function to navigate through single elements


#1

Hi guys, here is a small function wich may help some of you. It allows to navigate trough single item without the lightbox activated. You know can navigate trough the gallery with simple links (previous/next media).

Simply past this function in your functions.php :

function rtmedia_navigate() {  
    global $wpdb, $rtmedia_media;   

    $current_media = rtmedia_id();  
    $current_album = $rtmedia_media->album_id;  
    $media_ID = array();  
    $content = "";  

    $medias = $wpdb->get_results ( "SELECT ID FROM ".$wpdb->prefix."rt_rtm_media WHERE album_id = $current_album ORDER BY ID" );  
    foreach( $medias as $media_id ) {  
        $media_ID[]= $media_id->ID;  
    }  
    $current_key = array_search($current_media,$media_ID);  
    $prev_id = $media_ID[$current_key-1];  
    $next_id = $media_ID[$current_key+1];  

    if($prev_id != '' || $next_id != '') {  
        $content .= '
'; if($prev_id != '') { $prev_link = get_rtmedia_permalink($prev_id); $content .= 'Previous'; } if($next_id != '') { $next_link = get_rtmedia_permalink($next_id); $content .= 'Next'; } $content .= '
'; } print $content; }

Then past this in the loop of your custom media-single.php file :

<?php rtmedia_navigate(); ?>  

Hope this help !


#2

Small update wich show offset/total of current displayed pictures.

    function rtmedia_navigate() {  
    global $wpdb, $rtmedia_media;   

    $current_media = rtmedia_id();  
    $current_album = $rtmedia_media->album_id;  
    $media_ID = array();  

    $medias = $wpdb->get_results ( "SELECT ID FROM ".$wpdb->prefix."rt_rtm_media WHERE album_id = $current_album ORDER BY ID" );  
    foreach( $medias as $media_id ) {  
        $media_ID[]= $media_id->ID;  
    }  
    $current_key = array_search($current_media,$media_ID);  
    $counter = count($media_ID);  
    $prev_id = $media_ID[$current_key-1];  
    $next_id = $media_ID[$current_key+1];  

    if($prev_id != '' || $next_id != '') {  
            $content .= '
'; if($prev_id != '') { $prev_link = get_rtmedia_permalink($prev_id); $content .= 'Previous'; } $content .= '
'.($current_key+1).'/'.$counter.'
'; if($next_id != '') { $next_link = get_rtmedia_permalink($next_id); $content .= 'Next'; } $content .= '
'; } print $content; }

#3

And where do i find custom media-single.php file. Please give me a path


#4

Hi michael,

You will need to override the media-single.php file. You can find more info on overridding templates over here : https://rtcamp.com/rtmedia/docs/developer/templating-system/


#5

Hi,
Yep, as Pushpak said, you just have to copy the orignial media-single.php into your theme folder (read the doc before) to past the function call on it.

Here is another update with bug fixe when navigate through “wall album”.

function rtmedia_navigate() {  
	global $wpdb, $rtmedia_media;   
	$content = null;  
	$current_media = rtmedia_id();  
	$current_album = $rtmedia_media->album_id;  
	$current_ = $wpdb->get_results( "SELECT media_author,context,context_id FROM ".$wpdb->prefix."rt_rtm_media WHERE ID = $current_media LIMIT 1");  
	$current_user = $current_[0]->media_author;  
	$current_context = $current_[0]->context;  
	$current_context_id = $current_[0]->context_id;  

	$media_ID = array();  
	if($current_context == 'profile'){  
		$medias = $wpdb->get_results( "SELECT ID FROM ".$wpdb->prefix."rt_rtm_media WHERE album_id = $current_album AND media_author = $current_user AND context_id = $current_context_id ORDER BY ID" );  
	} else if($current_context == 'group'){  
		$medias = $wpdb->get_results( "SELECT ID FROM ".$wpdb->prefix."rt_rtm_media WHERE album_id = $current_album AND context_id = $current_context_id ORDER BY ID" );  
	}  
	foreach( $medias as $media_id ) {  
		$media_ID[]= $media_id->ID;  
	}  
	$current_key = array_search($current_media,$media_ID);  
	$counter = count($media_ID);  
	if(!empty($media_ID[$current_key-1])){  
		$prev_id = $media_ID[$current_key-1];  
	}  
	if(!empty($media_ID[$current_key+1])){  
		$next_id = $media_ID[$current_key+1];  
	}  
	  
	if(isset($prev_id) || isset($next_id)) {  
			$content .= '
'; if(isset($prev_id)) { $prev_link = get_rtmedia_permalink($prev_id); $content .= ''; } $content .= '
'.($current_key+1).'/'.$counter.'
'; if(isset($next_id)) { $next_link = get_rtmedia_permalink($next_id); $content .= ''; } $content .= '
'; '; } print $content; }

Cheerse


#6

This is not working for me. Inserting this code breaks my site.

Why can't you just put this option in your plugin settings.

I have so many template overides at the moment, and 90% of the things i change, are things which I really do not understand why are not pre-built in your plugin.

Things that i would consider basic must haves, and standard options that should be there from the start


#7