• Resolved oujele

    (@oujele)


    Hi,

    I am using “FooGallery Albums” extension and wanted to ask if there’s a possibility to add previous/next buttons inside the gallery so users could navigate through different albums inside the gallery itself?

    To get the clearer picture on what I am getting to – for example person clicks on Album page, every album thumbnail is there. Person clicks on one of the thumbnails and that album gallery opens up. But on the top left and right sides of the opened gallery there is “Previous gallery” and “Next gallery” buttons. You can click on either of them and it redirects to the previous/next gallery accordingly.

    Any help would be appreciated.

    Thank you.

    • This topic was modified 4 years, 3 months ago by oujele.
    • This topic was modified 4 years, 3 months ago by oujele.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter oujele

    (@oujele)

    Just to add, the code below is what I am looking for but it switches between albums. What variables I should use so it would switch between the galleries inside each album?

    add_shortcode( 'prev', 'prev_shortcode' );
    add_shortcode( 'next', 'next_shortcode' );
    function next_shortcode($atts) {
        global $post;
        ob_start(); 
        next_post_link( '<div class="nav-next">%link</div>', 'Next post link' );              
        $result = ob_get_contents();
        ob_end_clean();
        return $result;
    }
    
    function prev_shortcode($atts) {
        global $post;
        ob_start();
        previous_post_link( '<div class="nav-previous">%link</div>', 'Previous post link' );              
        $result = ob_get_contents();
        ob_end_clean();
        return $result;
    }
    Plugin Author bradvin

    (@bradvin)

    hi @oujele

    There is nothing built into FooGallery to give you that info, but if you add these snippets to your functions.php you can use them to get back the previous and next gallery ID’s based on the current gallery.

    function foogallery_album_find_next_gallery_id( $album, $gallery_id ) {
    	$return = false;
    	foreach ( $album->galleries() as $gallery ) {
    		if ( $return ) {
    			return $gallery->ID;
    		}
    
    		if ( $gallery->ID === $gallery_id ) {
    			$return = true;
    		}
    	}
    	return null;
    }
    
    function foogallery_album_find_previous_gallery_id( $album, $gallery_id ) {
    	$previous_id = false;
    	foreach ( $album->galleries() as $gallery ) {
    		if ( $gallery->ID === $gallery_id ) {
    			return $previous_id;
    		}
    
    		$previous_id = $gallery->ID;
    	}
    	return $previous_id;
    }

    And then you could use the functions inside a custom album template like this:

    
    	echo 'Previous : ' . foogallery_album_find_previous_gallery_id( $current_foogallery_album, $foogallery->ID );
    	echo 'Next : ' . foogallery_album_find_next_gallery_id( $current_foogallery_album, $foogallery->ID );
    
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘FooGallery previous next’ is closed to new replies.